diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.ts index d6f5c4bf67..0c6ebb396b 100644 --- a/web/apps/accounts/src/services/passkey.ts +++ b/web/apps/accounts/src/services/passkey.ts @@ -61,36 +61,6 @@ export const deletePasskey = async (id: string) => { } }; -export const getPasskeyRegistrationOptions = async () => { - try { - const token = getToken(); - if (!token) return; - const response = await HTTPService.get( - `${ENDPOINT}/passkeys/registration/begin`, - {}, - { - "X-Auth-Token": token, - }, - ); - return await response.data; - } catch (e) { - log.error("get passkey registration options failed", e); - throw e; - } -}; - -/** - * Return `true` if the given {@link redirectURL} (obtained from the redirect - * query parameter passed around during the passkey verification flow) is one of - * the whitelisted URLs that we allow redirecting to on success. - */ -export const isWhitelistedRedirect = (redirectURL: URL) => - (isDevBuild && redirectURL.hostname.endsWith("localhost")) || - redirectURL.host.endsWith(".ente.io") || - redirectURL.host.endsWith(".ente.sh") || - redirectURL.protocol == "ente:" || - redirectURL.protocol == "enteauth:"; - /** * Add a new passkey as the second factor to the user's account. * @@ -125,6 +95,24 @@ export const registerPasskey = async (name: string) => { await finishPasskeyRegistration(name, credential, response.sessionID); }; +export const getPasskeyRegistrationOptions = async () => { + try { + const token = getToken(); + if (!token) return; + const response = await HTTPService.get( + `${ENDPOINT}/passkeys/registration/begin`, + {}, + { + "X-Auth-Token": token, + }, + ); + return await response.data; + } catch (e) { + log.error("get passkey registration options failed", e); + throw e; + } +}; + const finishPasskeyRegistration = async ( friendlyName: string, credential: Credential, @@ -165,6 +153,18 @@ const finishPasskeyRegistration = async ( return await response.data; }; +/** + * Return `true` if the given {@link redirectURL} (obtained from the redirect + * query parameter passed around during the passkey verification flow) is one of + * the whitelisted URLs that we allow redirecting to on success. + */ +export const isWhitelistedRedirect = (redirectURL: URL) => + (isDevBuild && redirectURL.hostname.endsWith("localhost")) || + redirectURL.host.endsWith(".ente.io") || + redirectURL.host.endsWith(".ente.sh") || + redirectURL.protocol == "ente:" || + redirectURL.protocol == "enteauth:"; + export interface BeginPasskeyAuthenticationResponse { ceremonySessionID: string; options: Options;