Skip to content

Commit 700809f

Browse files
Add init support for a recovery using token feature
1 parent fd8a5d9 commit 700809f

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
import * as React from "react";
17+
import { getQueryParams } from "../../../../../utils";
18+
19+
export const RecoverAccountUsingToken = (props): JSX.Element => {
20+
const token = getQueryParams("token");
21+
console.log("token: ", token);
22+
23+
return <div>Recovering using token</div>;
24+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
export const DEFAULT_WEBAUTHN_RECOVERY_PATH = "/webauthn/recover";

lib/ts/recipe/webauthn/prebuiltui.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import NormalisedURLPath from "supertokens-web-js/lib/build/normalisedURLPath";
2+
13
import UserContextWrapper from "../../usercontext/userContextWrapper";
2-
import { isTest } from "../../utils";
4+
import { isTest, matchRecipeIdUsingQueryParams } from "../../utils";
35
import { FactorIds } from "../multifactorauth";
46
import { RecipeRouter } from "../recipeRouter";
57
import SessionAuth from "../session/sessionAuth";
68

79
import { useRecipeComponentOverrideContext } from "./componentOverrideContext";
10+
import { RecoverAccountUsingToken } from "./components/features/recoverAccountWithToken";
811
import SignInWithPasskeyFeature from "./components/features/signIn";
912
import SignUpFeature, { SignUpWithPasskeyFeature } from "./components/features/signUp";
1013
import { defaultTranslationsWebauthn } from "./components/themes/translations";
14+
import { DEFAULT_WEBAUTHN_RECOVERY_PATH } from "./constants";
1115
import WebauthnRecipe from "./recipe";
1216

1317
import type { GenericComponentOverrideMap } from "../../components/componentOverride/componentOverrideContext";
@@ -42,7 +46,7 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
4246
return WebauthnPreBuiltUI.getInstanceOrInitAndGetInstance().getFeatures(useComponentOverrides);
4347
}
4448
static getFeatureComponent(
45-
componentName: "webauthn-sign-up",
49+
componentName: "webauthn-recover-account",
4650
props: FeatureBaseProps<{ userContext?: UserContext }>,
4751
useComponentOverrides: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
4852
): JSX.Element {
@@ -55,23 +59,33 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
5559

5660
// Instance methods
5761
getFeatures = (
58-
_: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
62+
useComponentOverrides: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
5963
): RecipeFeatureComponentMap => {
6064
const features: RecipeFeatureComponentMap = {};
61-
// TODO: Define after components are defined
65+
if (this.recipeInstance.config.disableDefaultUI !== true) {
66+
const normalisedFullPath = this.recipeInstance.config.appInfo.websiteBasePath.appendPath(
67+
new NormalisedURLPath(DEFAULT_WEBAUTHN_RECOVERY_PATH)
68+
);
69+
features[normalisedFullPath.getAsStringDangerous()] = {
70+
matches: matchRecipeIdUsingQueryParams(this.recipeInstance.config.recipeId),
71+
component: (props: any) =>
72+
this.getFeatureComponent("webauthn-recover-account", props, useComponentOverrides),
73+
recipeID: WebauthnRecipe.RECIPE_ID,
74+
};
75+
}
6276
return features;
6377
};
6478

6579
getFeatureComponent = (
66-
componentName: "webauthn-sign-up",
80+
componentName: "webauthn-recover-account",
6781
props: FeatureBaseProps<{ userContext?: UserContext }>,
6882
_: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
6983
): JSX.Element => {
70-
if (componentName === "webauthn-sign-up") {
84+
if (componentName === "webauthn-recover-account") {
7185
return (
7286
<UserContextWrapper userContext={props.userContext}>
7387
<SessionAuth requireAuth={false} doRedirection={false}>
74-
<div></div>
88+
<RecoverAccountUsingToken />
7589
</SessionAuth>
7690
</UserContextWrapper>
7791
);

lib/ts/recipe/webauthn/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export type NormalisedSignUpFormFeatureConfig = NormalisedBaseConfig & {
122122

123123
export type NormalisedConfig = {
124124
signUpFeature: NormalisedSignUpFormFeatureConfig;
125+
disableDefaultUI?: boolean;
125126

126127
override: {
127128
functions: (originalImplementation: RecipeInterface) => RecipeInterface;

stories/allrecipes.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ export const SignInPasskey: Story = {
133133
},
134134
};
135135

136+
export const RecoverAccountWithToken: Story = {
137+
args: {
138+
path: "/auth/webauthn/recover",
139+
"multifactorauth.initialized": false,
140+
"passwordless.initialized": false,
141+
"webauthn.initialized": true,
142+
query: "token=asdf",
143+
},
144+
};
145+
136146
export const SignUpFieldErrors: Story = {
137147
args: {
138148
path: "/auth",

0 commit comments

Comments
 (0)