Skip to content

Commit 13e68ad

Browse files
Add some fixes for webauthn
1 parent ebcbc17 commit 13e68ad

File tree

9 files changed

+15480
-33368
lines changed

9 files changed

+15480
-33368
lines changed

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,51 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15+
/*
16+
* Imports.
17+
*/
18+
import * as React from "react";
19+
20+
import AuthComponentWrapper from "../../../../../components/authCompWrapper";
21+
import FeatureWrapper from "../../../../../components/featureWrapper";
22+
import SuperTokens from "../../../../../superTokens";
23+
import { ContinueWithPasskeyTheme } from "../../themes/continueWithPasskey";
24+
import { defaultTranslationsWebauthn } from "../../themes/translations";
25+
26+
import type { UserContext, PartialAuthComponentProps } from "../../../../../types";
27+
import type Recipe from "../../../recipe";
28+
import type { ComponentOverrideMap } from "../../../types";
29+
30+
export const SignInWithPasskeyFeature: React.FC<
31+
PartialAuthComponentProps & {
32+
recipe: Recipe;
33+
factorIds: string[];
34+
userContext?: UserContext;
35+
useComponentOverrides: () => ComponentOverrideMap;
36+
}
37+
> = (props) => {
38+
const recipeComponentOverrides = props.useComponentOverrides();
39+
40+
return (
41+
<AuthComponentWrapper recipeComponentOverrides={recipeComponentOverrides}>
42+
{/* <FeatureWrapper
43+
useShadowDom={SuperTokens.getInstanceOrThrow().useShadowDom}
44+
defaultStore={defaultTranslationsWebauthn}>
45+
<ContinueWithPasskeyTheme
46+
{...props}
47+
continueWithPasskeyClicked={() => props.setFactorList(props.factorIds)}
48+
config={props.recipe.config}
49+
continueFor="SIGN_IN"
50+
/>
51+
</FeatureWrapper> */}
52+
<ContinueWithPasskeyTheme
53+
{...props}
54+
continueWithPasskeyClicked={() => props.setFactorList(props.factorIds)}
55+
config={props.recipe.config}
56+
continueFor="SIGN_IN"
57+
/>
58+
</AuthComponentWrapper>
59+
);
60+
};
1561

16-
// TODO: Define later with more code
62+
export default SignInWithPasskeyFeature;

lib/ts/recipe/webauthn/prebuiltui.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { RecipeRouter } from "../recipeRouter";
55
import SessionAuth from "../session/sessionAuth";
66

77
import { useRecipeComponentOverrideContext } from "./componentOverrideContext";
8-
import ContinueWithPasskeyFeature from "./components/features/continueWithPasskey";
8+
import SignInWithPasskeyFeature from "./components/features/signIn";
9+
import { defaultTranslationsWebauthn } from "./components/themes/translations";
910
import WebauthnRecipe from "./recipe";
1011

1112
import type { GenericComponentOverrideMap } from "../../components/componentOverride/componentOverrideContext";
@@ -19,9 +20,7 @@ import type {
1920

2021
export class WebauthnPreBuiltUI extends RecipeRouter {
2122
static instance?: WebauthnPreBuiltUI;
22-
languageTranslations = {
23-
en: {},
24-
};
23+
languageTranslations = defaultTranslationsWebauthn;
2524

2625
constructor(public readonly recipeInstance: WebauthnRecipe) {
2726
super();
@@ -42,7 +41,7 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
4241
return WebauthnPreBuiltUI.getInstanceOrInitAndGetInstance().getFeatures(useComponentOverrides);
4342
}
4443
static getFeatureComponent(
45-
componentName: "sign-up" | "sign-in",
44+
componentName: "webauthn-sign-up",
4645
props: FeatureBaseProps<{ userContext?: UserContext }>,
4746
useComponentOverrides: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
4847
): JSX.Element {
@@ -63,35 +62,31 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
6362
};
6463

6564
getFeatureComponent = (
66-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
67-
componentName: "sign-up" | "sign-in",
65+
componentName: "webauthn-sign-up",
6866
props: FeatureBaseProps<{ userContext?: UserContext }>,
6967
_: () => GenericComponentOverrideMap<any> = useRecipeComponentOverrideContext
7068
): JSX.Element => {
71-
if (componentName === "sign-up") {
69+
if (componentName === "webauthn-sign-up") {
7270
return (
7371
<UserContextWrapper userContext={props.userContext}>
7472
<SessionAuth requireAuth={false} doRedirection={false}>
7573
<div></div>
7674
</SessionAuth>
7775
</UserContextWrapper>
7876
);
79-
} else if (componentName === "sign-in") {
80-
// TODO: Define this once sign-in is ready.
81-
return <div></div>;
8277
}
8378
throw new Error("Should never come here.");
8479
};
8580

8681
getAuthComponents(): AuthComponent[] {
87-
const res: AuthComponent[] = [
82+
return [
8883
{
8984
type: "SIGN_UP" as const,
9085
factorIds: [FactorIds.WEBAUTHN],
9186
displayOrder: 4,
87+
/* TODO: Update the following to be sign up instead of sign in */
9288
component: (props: PartialAuthComponentProps) => (
93-
<ContinueWithPasskeyFeature
94-
continueFor="SIGN_UP"
89+
<SignInWithPasskeyFeature
9590
key="webauthn-sign-up"
9691
{...props}
9792
recipe={this.recipeInstance}
@@ -100,9 +95,21 @@ export class WebauthnPreBuiltUI extends RecipeRouter {
10095
/>
10196
),
10297
},
98+
{
99+
type: "SIGN_IN" as const,
100+
factorIds: [FactorIds.WEBAUTHN],
101+
displayOrder: 4,
102+
component: (props: PartialAuthComponentProps) => (
103+
<SignInWithPasskeyFeature
104+
key="webauthn-sign-in"
105+
{...props}
106+
recipe={this.recipeInstance}
107+
factorIds={[FactorIds.WEBAUTHN]}
108+
useComponentOverrides={useRecipeComponentOverrideContext}
109+
/>
110+
),
111+
},
103112
];
104-
105-
return res;
106113
}
107114

108115
// For tests

lib/ts/recipe/webauthn/recipe.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class Webauthn extends AuthRecipe<
4343
NormalisedConfig
4444
> {
4545
static instance?: Webauthn;
46-
static RECIPE_ID = "passwordless";
46+
static RECIPE_ID = "webauthn";
4747

4848
recipeID = Webauthn.RECIPE_ID;
4949
firstFactorIds = [];

lib/ts/recipe/webauthn/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export type OnHandleEventContext =
9595
}
9696
| AuthRecipeModuleOnHandleEventContext;
9797

98-
export type UserInput = Record<string, unknown> & {
98+
export type UserInput = {} & {
9999
override?: {
100100
functions?: (originalImplementation: RecipeInterface) => RecipeInterface;
101101
};

0 commit comments

Comments
 (0)