Skip to content

Commit 0d3b409

Browse files
Add support for a proper sign up theme component
1 parent 93023f8 commit 0d3b409

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import { useRethrowInRender } from "../../../../../utils";
2727
import Session from "../../../../session/recipe";
2828
import useSessionContext from "../../../../session/useSessionContext";
2929
import { ContinueWithPasskeyTheme } from "../../themes/continueWithPasskey";
30+
import SignUpTheme from "../../themes/signUp";
3031
import { defaultTranslationsWebauthn } from "../../themes/translations";
31-
// import SignUpThemeWrapper from "../../themes/signInUp";
3232

3333
import type { UserContext, PartialAuthComponentProps } from "../../../../../types";
3434
import type { AuthSuccessContext } from "../../../../authRecipe/types";
3535
import type Recipe from "../../../recipe";
3636
import type { ComponentOverrideMap } from "../../../types";
37-
import type { SignUpChildProps } from "../../../types";
37+
import type { SignUpThemeProps } from "../../../types";
3838
import type { User } from "supertokens-web-js/types";
3939

4040
export function useChildProps(
@@ -44,7 +44,7 @@ export function useChildProps(
4444
error: string | undefined,
4545
onError: (err: string) => void,
4646
userContext: UserContext
47-
): SignUpChildProps {
47+
): SignUpThemeProps {
4848
const session = useSessionContext();
4949
const recipeImplementation = recipe.webJSRecipe;
5050
const rethrowInRender = useRethrowInRender();
@@ -109,8 +109,7 @@ const SignUpFeatureInner: React.FC<
109109
return (
110110
<Fragment>
111111
{/* No custom theme, use default. */}
112-
{/* {props.children === undefined && <SignUpThemeWrapper {...childProps} />} */}
113-
{props.children === undefined && <div></div>}
112+
{props.children === undefined && <SignUpTheme {...childProps} />}
114113

115114
{/* Otherwise, custom theme is provided, propagate props. */}
116115
{props.children &&
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 SuperTokens from "../../../../../superTokens";
17+
import UserContextWrapper from "../../../../../usercontext/userContextWrapper";
18+
import { ThemeBase } from "../themeBase";
19+
20+
import type { SignUpThemeProps } from "../../../types";
21+
22+
function SignUpTheme(props: SignUpThemeProps): JSX.Element {
23+
const rootStyle = SuperTokens.getInstanceOrThrow().rootStyle;
24+
25+
const activeStyle = props.config.signUpFeature.style;
26+
27+
return (
28+
<UserContextWrapper userContext={props.userContext}>
29+
<ThemeBase userStyles={[rootStyle, props.config.recipeRootStyle, activeStyle]}>
30+
<div></div>
31+
</ThemeBase>
32+
</UserContextWrapper>
33+
);
34+
}
35+
36+
export default SignUpTheme;

lib/ts/recipe/webauthn/types.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import type {
1717
FeatureBaseConfig,
18+
NormalisedBaseConfig,
19+
NormalisedFormField,
1820
NormalisedGetRedirectionURLContext,
1921
UserContext,
2022
WebJSRecipeInterface,
@@ -25,6 +27,7 @@ import type {
2527
NormalisedConfig as NormalisedAuthRecipeModuleConfig,
2628
Config as AuthRecipeModuleConfig,
2729
} from "../authRecipe/types";
30+
import type { InputProps } from "../emailpassword/components/library/input";
2831
import type WebJSRecipe from "supertokens-web-js/recipe/webauthn";
2932
import type { RecipeInterface } from "supertokens-web-js/recipe/webauthn";
3033
import type { User } from "supertokens-web-js/types";
@@ -95,7 +98,7 @@ export type OnHandleEventContext =
9598
}
9699
| AuthRecipeModuleOnHandleEventContext;
97100

98-
export type UserInput = {} & {
101+
export type UserInput = Record<string, unknown> & {
99102
override?: {
100103
functions?: (originalImplementation: RecipeInterface) => RecipeInterface;
101104
};
@@ -106,7 +109,18 @@ export type UserInput = {} & {
106109
export type Config = UserInput &
107110
AuthRecipeModuleConfig<GetRedirectionURLContext, PreAndPostAPIHookAction, OnHandleEventContext>;
108111

112+
export type NormalisedSignUpFormFeatureConfig = NormalisedBaseConfig & {
113+
/*
114+
* Normalised form fields for SignUp.
115+
*/
116+
formFields: (NormalisedFormField & {
117+
inputComponent?: (props: InputProps) => JSX.Element;
118+
})[];
119+
};
120+
109121
export type NormalisedConfig = {
122+
signUpFeature: NormalisedSignUpFormFeatureConfig;
123+
110124
override: {
111125
functions: (originalImplementation: RecipeInterface) => RecipeInterface;
112126
};
@@ -122,7 +136,7 @@ export type WebauthnSignUpState = {
122136
error: string | undefined;
123137
};
124138

125-
export type SignUpChildProps = {
139+
export type SignUpThemeProps = {
126140
recipeImplementation: RecipeImplementation;
127141
factorIds: string[];
128142
config: NormalisedConfig;

0 commit comments

Comments
 (0)