Skip to content

Commit 7d71500

Browse files
Add support for handling email already exists in signup
1 parent 20116d5 commit 7d71500

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

lib/build/recipe/webauthn/components/themes/translations.d.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/webauthnprebuiltui.js

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export const SignUpForm = (
126126
): JSX.Element | null => {
127127
const [continueClickResponse, setContinueClickResponse] = useState<ContinueOnSuccessParams | null>(null);
128128
const userContext = useUserContext();
129-
const [showPasskeyConfirmationError, setShowPasskeyConfirmationError] = useState(false);
129+
const [errorLabel, setErrorLabel] = useState<string | undefined>(undefined);
130130
const [isLoading, setIsLoading] = useState(false);
131131

132132
const onContinueClickCallback = useCallback(
@@ -153,7 +153,11 @@ export const SignUpForm = (
153153
response.status === "FAILED_TO_REGISTER_USER" ||
154154
response.status === "AUTHENTICATOR_ALREADY_REGISTERED"
155155
) {
156-
setShowPasskeyConfirmationError(true);
156+
setErrorLabel("WEBAUTHN_PASSKEY_RECOVERABLE_ERROR");
157+
}
158+
159+
if (response.status === "EMAIL_ALREADY_EXISTS_ERROR") {
160+
setErrorLabel("WEBAUTHN_EMAIL_ALREADY_EXISTS_ERROR");
157161
}
158162

159163
return response;
@@ -175,14 +179,14 @@ export const SignUpForm = (
175179
if (generalError !== undefined) {
176180
props.setActiveScreen(SignUpScreen.Error);
177181
} else if (fetchError !== undefined) {
178-
setShowPasskeyConfirmationError(true);
182+
setErrorLabel("WEBAUTHN_PASSKEY_RECOVERABLE_ERROR");
179183
} else {
180184
// If successful
181185
if (result.status === "OK") {
182186
if (setIsLoading) {
183187
setIsLoading(false);
184188
}
185-
setShowPasskeyConfirmationError(false);
189+
setErrorLabel(undefined);
186190
if (props.onSuccess !== undefined) {
187191
props.onSuccess(result);
188192
}
@@ -204,7 +208,7 @@ export const SignUpForm = (
204208
{...props}
205209
email={continueClickResponse?.email || ""}
206210
onContinueClick={onConfirmationClick}
207-
errorMessageLabel={showPasskeyConfirmationError ? "WEBAUTHN_PASSKEY_RECOVERABLE_ERROR" : undefined}
211+
errorMessageLabel={errorLabel}
208212
isLoading={isLoading}
209213
/>
210214
) : props.activeScreen === SignUpScreen.Error ? (

lib/ts/recipe/webauthn/components/themes/translations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ export const defaultTranslationsWebauthn = {
4646
"The passkey is invalid, please try again, possibly with a different device.",
4747
WEBAUTHN_ACCOUNT_RECOVERY_GENERATED_OPTIONS_NOT_FOUND_ERROR: "Failed to recover account, please try again.",
4848
WEBAUTHN_ACCOUNT_RECOVERY_INVALID_AUTHENTICATOR_ERROR: "Invalid authenticator, please try again.",
49+
WEBAUTHN_EMAIL_ALREADY_EXISTS_ERROR: "Email already exists, please sign in instead.",
4950
},
5051
};

0 commit comments

Comments
 (0)