Skip to content

Commit ff08dd7

Browse files
Add some fixes for the webauthn sign up /in functionality
1 parent f9331e0 commit ff08dd7

File tree

4 files changed

+62
-12
lines changed

4 files changed

+62
-12
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,20 @@ export const SignInWithPasskeyFeature: React.FC<
3737
> = (props) => {
3838
const recipeComponentOverrides = props.useComponentOverrides();
3939

40+
// TODO: Define the code to handle sign in properly through this component.
41+
const handleWebauthnSignInClick = () => {
42+
alert("This is yet to be defined!");
43+
return;
44+
};
45+
4046
return (
4147
<AuthComponentWrapper recipeComponentOverrides={recipeComponentOverrides}>
4248
<FeatureWrapper
4349
useShadowDom={SuperTokens.getInstanceOrThrow().useShadowDom}
4450
defaultStore={defaultTranslationsWebauthn}>
4551
<ContinueWithPasskeyTheme
4652
{...props}
47-
continueWithPasskeyClicked={() => props.setFactorList(props.factorIds)}
53+
continueWithPasskeyClicked={handleWebauthnSignInClick}
4854
config={props.recipe.config}
4955
continueFor="SIGN_IN"
5056
/>

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ import { Fragment } from "react";
2020
import { useMemo } from "react";
2121

2222
import AuthComponentWrapper from "../../../../../components/authCompWrapper";
23+
import FeatureWrapper from "../../../../../components/featureWrapper";
24+
import SuperTokens from "../../../../../superTokens";
2325
import { useUserContext } from "../../../../../usercontext";
2426
import { useRethrowInRender } from "../../../../../utils";
2527
import Session from "../../../../session/recipe";
2628
import useSessionContext from "../../../../session/useSessionContext";
29+
import { ContinueWithPasskeyTheme } from "../../themes/continueWithPasskey";
30+
import { defaultTranslationsWebauthn } from "../../themes/translations";
2731
// import SignUpThemeWrapper from "../../themes/signInUp";
2832

2933
import type { UserContext, PartialAuthComponentProps } from "../../../../../types";
@@ -39,9 +43,7 @@ export function useChildProps(
3943
onAuthSuccess: (successContext: AuthSuccessContext) => Promise<void>,
4044
error: string | undefined,
4145
onError: (err: string) => void,
42-
// clearError: () => void,
4346
userContext: UserContext
44-
// navigate?: Navigate
4547
): SignUpChildProps {
4648
const session = useSessionContext();
4749
const recipeImplementation = recipe.webJSRecipe;
@@ -101,9 +103,7 @@ const SignUpFeatureInner: React.FC<
101103
props.onAuthSuccess,
102104
props.error,
103105
props.onError,
104-
// props.clearError,
105106
userContext
106-
// props.navigate
107107
)!;
108108

109109
return (
@@ -143,4 +143,30 @@ export const SignUpFeature: React.FC<
143143
);
144144
};
145145

146+
export const SignUpWithPasskeyFeature: React.FC<
147+
PartialAuthComponentProps & {
148+
recipe: Recipe;
149+
factorIds: string[];
150+
userContext?: UserContext;
151+
useComponentOverrides: () => ComponentOverrideMap;
152+
}
153+
> = (props) => {
154+
const recipeComponentOverrides = props.useComponentOverrides();
155+
156+
return (
157+
<AuthComponentWrapper recipeComponentOverrides={recipeComponentOverrides}>
158+
<FeatureWrapper
159+
useShadowDom={SuperTokens.getInstanceOrThrow().useShadowDom}
160+
defaultStore={defaultTranslationsWebauthn}>
161+
<ContinueWithPasskeyTheme
162+
{...props}
163+
continueWithPasskeyClicked={() => props.setFactorList(props.factorIds)}
164+
config={props.recipe.config}
165+
continueFor="SIGN_UP"
166+
/>
167+
</FeatureWrapper>
168+
</AuthComponentWrapper>
169+
);
170+
};
171+
146172
export default SignUpFeature;

lib/ts/recipe/webauthn/prebuiltui.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SessionAuth from "../session/sessionAuth";
66

77
import { useRecipeComponentOverrideContext } from "./componentOverrideContext";
88
import SignInWithPasskeyFeature from "./components/features/signIn";
9+
import SignUpFeature, { SignUpWithPasskeyFeature } from "./components/features/signUp";
910
import { defaultTranslationsWebauthn } from "./components/themes/translations";
1011
import WebauthnRecipe from "./recipe";
1112

@@ -80,13 +81,30 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
8081

8182
getAuthComponents(): AuthComponent[] {
8283
return [
84+
{
85+
type: "FULL_PAGE",
86+
async preloadInfoAndRunChecks(firstFactors) {
87+
return {
88+
shouldDisplay: firstFactors.length === 1 && firstFactors.includes(FactorIds.WEBAUTHN),
89+
preloadInfo: {},
90+
};
91+
},
92+
component: (props) => (
93+
<SignUpFeature
94+
key="webauthnSignUpFullPage"
95+
{...props}
96+
recipe={this.recipeInstance}
97+
useComponentOverrides={useRecipeComponentOverrideContext}
98+
factorIds={[FactorIds.WEBAUTHN]}
99+
/>
100+
),
101+
},
83102
{
84103
type: "SIGN_UP" as const,
85104
factorIds: [FactorIds.WEBAUTHN],
86105
displayOrder: 4,
87-
/* TODO: Update the following to be sign up instead of sign in */
88106
component: (props: PartialAuthComponentProps) => (
89-
<SignInWithPasskeyFeature
107+
<SignUpWithPasskeyFeature
90108
key="webauthn-sign-up"
91109
{...props}
92110
recipe={this.recipeInstance}

stories/allrecipes.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ export const SignUpPasskey: Story = {
115115
},
116116
play: async ({ canvasElement }) => {
117117
// Assigns canvas to the component root element
118-
const canvas = within(canvasElement);
119-
const switcher = await canvas.findByText("CONTINUE WITH PASSKEY");
120-
await new Promise((res) => setTimeout(res, 100));
121-
canvasElement;
122-
await userEvent.click(switcher, { delay: 200 });
118+
// const canvas = within(canvasElement);
119+
// const switcher = await canvas.findByText("CONTINUE WITH PASSKEY");
120+
// await new Promise((res) => setTimeout(res, 100));
121+
// canvasElement;
122+
// await userEvent.click(switcher, { delay: 200 });
123123
},
124124
};
125125

0 commit comments

Comments
 (0)