Skip to content

Commit 7ca8eac

Browse files
Add support for recovery email being a separate route on its own
1 parent 5476719 commit 7ca8eac

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

lib/ts/recipe/webauthn/components/themes/sendRecoveryEmail/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import GeneralError from "../../../../emailpassword/components/library/generalEr
99
import { ThemeBase } from "../themeBase";
1010

1111
import { PasskeyEmailSent } from "./emailSent";
12-
import { PasskeyRecoverAccountForm } from "./recoverAccountForm";
12+
import { PasskeyRecoverAccount } from "./recoverAccountForm";
1313

1414
import type { SendRecoveryEmailFormThemeProps } from "../../../types";
1515

@@ -39,11 +39,10 @@ export const SendRecoveryEmailFormThemeInner = (
3939
};
4040

4141
return props.activeScreen === SendRecoveryEmailScreen.RecoverAccount ? (
42-
<PasskeyRecoverAccountForm
42+
<PasskeyRecoverAccount
4343
onSuccess={onRecoverAccountFormSuccess}
4444
onBackClick={onRecoverAccountBackClick}
4545
recipeImplementation={props.recipeImplementation}
46-
setError={(error) => console.error(error)}
4746
/>
4847
) : props.activeScreen === SendRecoveryEmailScreen.RecoverEmailSent ? (
4948
<PasskeyEmailSent email={recoverAccountEmail} onEmailChangeClick={onEmailChangeClick} />

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ 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";
2627

2728
import { PasskeyConfirmation } from "./confirmation";
2829
import { ContinueWithoutPasskey } from "./continueWithoutPasskey";
@@ -75,7 +76,7 @@ export const SignUpFormInner = withOverride(
7576
<div data-supertokens="formLabelWithLinkWrapper">
7677
<Label value={"WEBAUTHN_SIGN_UP_LABEL"} data-supertokens="emailInputLabel" />
7778
<a
78-
onClick={() => console.error("Recover account link: to be defined")}
79+
href={DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH}
7980
data-supertokens="link linkButton formLabelLinkBtn recoverAccountTrigger">
8081
{t("WEBAUTHN_RECOVER_ACCOUNT_LABEL")}
8182
</a>

lib/ts/recipe/webauthn/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
* under the License.
1414
*/
1515
export const DEFAULT_WEBAUTHN_RECOVERY_PATH = "/webauthn/recover";
16+
17+
export const DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH = "/webauthn/recover/send-email";

lib/ts/recipe/webauthn/prebuiltui.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import SessionAuth from "../session/sessionAuth";
88

99
import { useRecipeComponentOverrideContext } from "./componentOverrideContext";
1010
import { RecoverAccountUsingToken } from "./components/features/recoverAccountWithToken";
11+
import { SendRecoveryEmailForm } from "./components/features/sendRecoveryEmail";
1112
import SignInWithPasskeyFeature from "./components/features/signIn";
1213
import SignUpFeature, { SignUpWithPasskeyFeature } from "./components/features/signUp";
1314
import { defaultTranslationsWebauthn } from "./components/themes/translations";
14-
import { DEFAULT_WEBAUTHN_RECOVERY_PATH } from "./constants";
15+
import { DEFAULT_WEBAUTHN_RECOVERY_PATH, DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH } from "./constants";
1516
import WebauthnRecipe from "./recipe";
1617

1718
import type { GenericComponentOverrideMap } from "../../components/componentOverride/componentOverrideContext";
@@ -46,7 +47,7 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
4647
return WebauthnPreBuiltUI.getInstanceOrInitAndGetInstance().getFeatures(useComponentOverrides);
4748
}
4849
static getFeatureComponent(
49-
componentName: "webauthn-recover-account",
50+
componentName: "webauthn-recover-account" | "webauthn-send-recovery-email",
5051
props: FeatureBaseProps<{ userContext?: UserContext }>,
5152
useComponentOverrides: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
5253
): JSX.Element {
@@ -72,12 +73,23 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
7273
this.getFeatureComponent("webauthn-recover-account", props, useComponentOverrides),
7374
recipeID: WebauthnRecipe.RECIPE_ID,
7475
};
76+
77+
const normalisedFullPathForRecoveryThroughEmail =
78+
this.recipeInstance.config.appInfo.websiteBasePath.appendPath(
79+
new NormalisedURLPath(DEFAULT_WEBAUTHN_SEND_RECOVERY_EMAIL_PATH)
80+
);
81+
features[normalisedFullPathForRecoveryThroughEmail.getAsStringDangerous()] = {
82+
matches: matchRecipeIdUsingQueryParams(this.recipeInstance.config.recipeId),
83+
component: (props: any) =>
84+
this.getFeatureComponent("webauthn-send-recovery-email", props, useComponentOverrides),
85+
recipeID: WebauthnRecipe.RECIPE_ID,
86+
};
7587
}
7688
return features;
7789
};
7890

7991
getFeatureComponent = (
80-
componentName: "webauthn-recover-account",
92+
componentName: "webauthn-recover-account" | "webauthn-send-recovery-email",
8193
props: FeatureBaseProps<{ userContext?: UserContext }>,
8294
useComponentOverrides: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
8395
): JSX.Element => {
@@ -93,6 +105,18 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
93105
</SessionAuth>
94106
</UserContextWrapper>
95107
);
108+
} else if (componentName === "webauthn-send-recovery-email") {
109+
return (
110+
<UserContextWrapper userContext={props.userContext}>
111+
<SessionAuth requireAuth={false} doRedirection={false}>
112+
<SendRecoveryEmailForm
113+
recipe={this.recipeInstance}
114+
{...props}
115+
useComponentOverrides={useComponentOverrides}
116+
/>
117+
</SessionAuth>
118+
</UserContextWrapper>
119+
);
96120
}
97121
throw new Error("Should never come here.");
98122
};

stories/allrecipes.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ export const RecoverAccountWithToken: Story = {
142142
},
143143
};
144144

145+
export const SendRecoveryEmail: Story = {
146+
args: {
147+
path: "/auth/webauthn/recover/send-email",
148+
"multifactorauth.initialized": false,
149+
"passwordless.initialized": false,
150+
"webauthn.initialized": true,
151+
},
152+
};
153+
145154
export const SignUpFieldErrors: Story = {
146155
args: {
147156
path: "/auth",

0 commit comments

Comments
 (0)