Rearrange

This commit is contained in:
Manav Rathi
2024-06-07 11:29:01 +05:30
parent 849adb8a0b
commit 6d4e434a8d

View File

@@ -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;