This commit is contained in:
Manav Rathi
2024-06-13 16:21:13 +05:30
parent f2928c8ab8
commit da853fdfde
3 changed files with 9 additions and 10 deletions

View File

@@ -14,8 +14,8 @@ import {
finishPasskeyAuthentication,
isWebAuthnSupported,
isWhitelistedRedirect,
passkeyAuthenticationSuccessRedirectURL,
redirectToPasskeyRecoverPage,
redirectURLWithPasskeyAuthentication,
signChallenge,
} from "services/passkey";
@@ -40,7 +40,7 @@ const Page = () => {
// The URL we're redirecting to on success.
//
// This will only be set when status is "redirecting*".
const [redirectURLWithData, setRedirectURLWithData] = useState<
const [successRedirectURL, setSuccessRedirectURL] = useState<
URL | undefined
>();
@@ -115,8 +115,8 @@ const Page = () => {
setStatus(isHTTP(redirectURL) ? "redirectingWeb" : "redirectingApp");
setRedirectURLWithData(
await redirectURLWithPasskeyAuthentication(
setSuccessRedirectURL(
await passkeyAuthenticationSuccessRedirectURL(
redirectURL,
passkeySessionID,
authorizationResponse,
@@ -129,8 +129,8 @@ const Page = () => {
}, []);
useEffect(() => {
if (redirectURLWithData) redirectToURL(redirectURLWithData);
}, [redirectURLWithData]);
if (successRedirectURL) redirectToURL(successRedirectURL);
}, [successRedirectURL]);
const handleRetry = () => void authenticate();
@@ -150,8 +150,7 @@ const Page = () => {
return () => redirectToPasskeyRecoverPage(new URL(recover));
})();
const handleRedirectAgain = () =>
redirectToURL(ensure(redirectURLWithData));
const handleRedirectAgain = () => redirectToURL(ensure(successRedirectURL));
const components: Record<Status, React.ReactNode> = {
loading: <Loading />,

View File

@@ -560,7 +560,7 @@ const authenticatorAssertionResponse = (credential: Credential) => {
* @param twoFactorAuthorizationResponse The result of
* {@link finishPasskeyAuthentication} returned by the backend.
*/
export const redirectURLWithPasskeyAuthentication = async (
export const passkeyAuthenticationSuccessRedirectURL = async (
redirectURL: URL,
passkeySessionID: string,
twoFactorAuthorizationResponse: TwoFactorAuthorizationResponse,

View File

@@ -50,7 +50,7 @@ export default Page;
*/
const saveCredentials = async (response: string) => {
// Decode response string (inverse of the steps we perform in
// `redirectAfterPasskeyAuthentication`).
// `passkeyAuthenticationSuccessRedirectURL`).
const decodedResponse = JSON.parse(
await fromB64URLSafeNoPaddingString(response),
);