|
1 | 1 | import parsePhoneNumberFromString from 'libphonenumber-js'; |
2 | | -import { startAuthentication } from '@simplewebauthn/browser'; |
3 | | -import { createFetchWithAuth } from './fetchWithAuth'; |
4 | 2 | /** |
5 | 3 | * isValidEmail |
6 | 4 | * |
@@ -102,78 +100,3 @@ export function parseUserAgent() { |
102 | 100 |
|
103 | 101 | return { platform, browser, deviceInfo }; |
104 | 102 | } |
105 | | - |
106 | | -// export const login = async ( |
107 | | -// fetchWithAuth: (input: string, init?: RequestInit) => Promise<Response>, |
108 | | -// identifier: string, |
109 | | -// passkeyAvailable: boolean |
110 | | -// ) => { |
111 | | -// // setFormErrors(''); |
112 | | - |
113 | | -// const response = await fetchWithAuth(`/login`, { |
114 | | -// method: 'POST', |
115 | | -// body: JSON.stringify({ identifier, passkeyAvailable }), |
116 | | -// }); |
117 | | -// console.log('response from /login', response); |
118 | | -// // if (!response.ok) { |
119 | | -// // setFormErrors('Failed to send login link. Please try again.'); |
120 | | -// // return; |
121 | | -// // } |
122 | | - |
123 | | -// if (!passkeyAvailable) { |
124 | | -// // setShowFallbackOptions(true); |
125 | | -// console.log |
126 | | -// return; |
127 | | -// } |
128 | | - |
129 | | -// try { |
130 | | -// await handlePasskeyLogin(fetchWithAuth); |
131 | | -// } catch (err) { |
132 | | -// console.error('Passkey login failed', err); |
133 | | -// // setShowFallbackOptions(true); |
134 | | -// } |
135 | | -// }; |
136 | | - |
137 | | -const handlePasskeyLogin = async ( |
138 | | - fetchWithAuth: (input: string, init?: RequestInit) => Promise<Response> |
139 | | -) => { |
140 | | - try { |
141 | | - const response = await fetchWithAuth(`/webAuthn/login/start`, { |
142 | | - method: 'POST', |
143 | | - }); |
144 | | - |
145 | | - if (!response.ok) { |
146 | | - console.error('Something went wrong getting webauthn options'); |
147 | | - return; |
148 | | - } |
149 | | - |
150 | | - const options = await response.json(); |
151 | | - const credential = await startAuthentication({ optionsJSON: options }); |
152 | | - |
153 | | - const verificationResponse = await fetchWithAuth(`/webAuthn/login/finish`, { |
154 | | - method: 'POST', |
155 | | - body: JSON.stringify({ assertionResponse: credential }), |
156 | | - }); |
157 | | - |
158 | | - if (!verificationResponse.ok) { |
159 | | - console.error('Failed to verify passkey'); |
160 | | - } |
161 | | - |
162 | | - const verificationResult = await verificationResponse.json(); |
163 | | - |
164 | | - // let them handle the below |
165 | | - // if (verificationResult.message === 'Success') { |
166 | | - // if (verificationResult.mfaLogin) { |
167 | | - // navigate('/mfaLogin'); |
168 | | - // return; |
169 | | - // } |
170 | | - // await validateToken(); |
171 | | - // navigate('/'); |
172 | | - // return; |
173 | | - // } else { |
174 | | - // console.error('Passkey login failed:', verificationResult.message); |
175 | | - // } |
176 | | - } catch (error) { |
177 | | - console.error('Passkey login error:', error); |
178 | | - } |
179 | | -}; |
0 commit comments