Skip to content

Commit 0d69bad

Browse files
Add support for properly redirecting on recover account click
1 parent 7ca8eac commit 0d69bad

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

lib/ts/recipe/webauthn/components/features/signUp/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { ContinueWithPasskeyTheme } from "../../themes/continueWithPasskey";
3030
import SignUpTheme from "../../themes/signUp";
3131
import { defaultTranslationsWebauthn } from "../../themes/translations";
3232

33-
import type { UserContext, PartialAuthComponentProps } from "../../../../../types";
33+
import type { UserContext, PartialAuthComponentProps, Navigate } from "../../../../../types";
3434
import type { AuthSuccessContext } from "../../../../authRecipe/types";
3535
import type Recipe from "../../../recipe";
3636
import type { ComponentOverrideMap } from "../../../types";
@@ -46,12 +46,16 @@ export function useChildProps(
4646
userContext: UserContext,
4747
clearError: () => void,
4848
resetFactorList: () => void,
49-
onSignInUpSwitcherClick: () => void
49+
onSignInUpSwitcherClick: () => void,
50+
navigate?: Navigate
5051
): SignUpThemeProps {
5152
const session = useSessionContext();
5253
const recipeImplementation = recipe.webJSRecipe;
5354
const rethrowInRender = useRethrowInRender();
5455

56+
const onRecoverAccountClick = () =>
57+
recipe.redirect({ action: "SEND_RECOVERY_EMAIL", tenantIdFromQueryParams: "" }, navigate, {}, userContext);
58+
5559
return useMemo(() => {
5660
return {
5761
userContext,
@@ -87,6 +91,7 @@ export function useChildProps(
8791
config: recipe.config,
8892
resetFactorList: resetFactorList,
8993
onSignInUpSwitcherClick,
94+
onRecoverAccountClick,
9095
};
9196
}, [error, factorIds, userContext, recipeImplementation]);
9297
}
@@ -112,7 +117,8 @@ const SignUpFeatureInner: React.FC<
112117
userContext,
113118
props.clearError,
114119
props.resetFactorList,
115-
props.onSignInUpSwitcherClick
120+
props.onSignInUpSwitcherClick,
121+
props.navigate
116122
)!;
117123

118124
return (

lib/ts/recipe/webauthn/components/themes/signUp/signUpForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { handleCallAPI } from "../../../../../utils";
2323
import { Label } from "../../../../emailpassword/components/library";
2424
import FormBase from "../../../../emailpassword/components/library/formBase";
2525
import { defaultEmailValidator } from "../../../../emailpassword/validators";
26-
import { DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH } from "../../../constants";
2726

2827
import { PasskeyConfirmation } from "./confirmation";
2928
import { ContinueWithoutPasskey } from "./continueWithoutPasskey";
@@ -46,6 +45,7 @@ export const SignUpFormInner = withOverride(
4645
footer?: JSX.Element;
4746
onContinueClick: (params: ContinueOnSuccessParams) => void;
4847
setActiveScreen: React.Dispatch<React.SetStateAction<SignUpScreen>>;
48+
onRecoverAccountClick: () => void;
4949
}
5050
): JSX.Element {
5151
const t = useTranslation();
@@ -76,7 +76,7 @@ export const SignUpFormInner = withOverride(
7676
<div data-supertokens="formLabelWithLinkWrapper">
7777
<Label value={"WEBAUTHN_SIGN_UP_LABEL"} data-supertokens="emailInputLabel" />
7878
<a
79-
href={DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH}
79+
onClick={props.onRecoverAccountClick}
8080
data-supertokens="link linkButton formLabelLinkBtn recoverAccountTrigger">
8181
{t("WEBAUTHN_RECOVER_ACCOUNT_LABEL")}
8282
</a>
@@ -121,6 +121,7 @@ export const SignUpForm = (
121121
onContinueClick: (params: ContinueOnSuccessParams) => void;
122122
activeScreen: SignUpScreen;
123123
setActiveScreen: React.Dispatch<React.SetStateAction<SignUpScreen>>;
124+
onRecoverAccountClick: () => void;
124125
}
125126
): JSX.Element | null => {
126127
const [continueClickResponse, setContinueClickResponse] = useState<ContinueOnSuccessParams | null>(null);

lib/ts/recipe/webauthn/recipe.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
import WebauthnWebJS from "supertokens-web-js/lib/build/recipe/webauthn";
1717

1818
import { SSR_ERROR } from "../../constants";
19+
import { getDefaultRedirectionURLForPath } from "../../utils";
1920
import AuthRecipe from "../authRecipe";
2021
import { FactorIds } from "../multifactorauth";
2122

23+
import { DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH } from "./constants";
2224
import { getFunctionOverrides } from "./functionOverrides";
2325
import { normaliseWebauthnConfig } from "./utils";
2426

@@ -65,6 +67,10 @@ export default class Webauthn extends AuthRecipe<
6567
}
6668

6769
getDefaultRedirectionURL = async (context: GetRedirectionURLContext): Promise<string> => {
70+
if (context.action === "SEND_RECOVERY_EMAIL") {
71+
return getDefaultRedirectionURLForPath(this.config, DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH, context);
72+
}
73+
6874
return this.getAuthRecipeDefaultRedirectionURL(context);
6975
};
7076

lib/ts/recipe/webauthn/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type GetRedirectionURLContext = NormalisedGetRedirectionURLContext<{
4343
/*
4444
* Get Redirection URL Context
4545
*/
46-
action: "RECOVER_ACCOUNT";
46+
action: "SEND_RECOVERY_EMAIL";
4747
}>;
4848

4949
export type PreAndPostAPIHookAction =
@@ -129,6 +129,7 @@ export type SignUpThemeProps = {
129129
userContext: UserContext;
130130
resetFactorList: () => void;
131131
onSignInUpSwitcherClick: () => void;
132+
onRecoverAccountClick: () => void;
132133
};
133134

134135
export type SignInThemeProps = SignUpThemeProps;

0 commit comments

Comments
 (0)