Skip to content

Commit a60197d

Browse files
Add support for handling recoverable errors in the UI
1 parent db6ca4b commit a60197d

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export const PasskeyConfirmation = withOverride(
2828
props: SignUpFormProps & {
2929
email: string;
3030
onContinueClick: () => void;
31+
errorMessageLabel?: string;
32+
isLoading: boolean;
3133
}
3234
): JSX.Element {
3335
const t = useTranslation();
@@ -39,10 +41,13 @@ export const PasskeyConfirmation = withOverride(
3941
<div data-supertokens="enteredEmailId">{props.email}</div>
4042
</div>
4143
<PasskeyFeatureBlocks />
44+
{props.errorMessageLabel !== undefined && props.errorMessageLabel !== "" && (
45+
<div data-supertokens="passkeyRecoverableErrorContainer">{t(props.errorMessageLabel)}</div>
46+
)}
4247
<div data-supertokens="passkeyConfirmationFooter">
4348
<Button
4449
disabled={false}
45-
isLoading={false}
50+
isLoading={props.isLoading}
4651
type="button"
4752
onClick={props.onContinueClick}
4853
label="WEBAUTHN_EMAIL_CONTINUE_BUTTON"

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export const SignUpForm = (
113113
): JSX.Element | null => {
114114
const [continueClickResponse, setContinueClickResponse] = useState<ContinueOnSuccessParams | null>(null);
115115
const userContext = useUserContext();
116+
const [showPasskeyConfirmationError, setShowPasskeyConfirmationError] = useState(false);
117+
const [isLoading, setIsLoading] = useState(false);
116118

117119
const onContinueClickCallback = useCallback(
118120
(params: ContinueOnSuccessParams) => {
@@ -139,8 +141,11 @@ export const SignUpForm = (
139141
const onConfirmationClick = useCallback(async () => {
140142
await handleFormSubmit({
141143
callAPI: callAPI,
142-
clearError: () => alert("Clearing error"),
143-
onError: (error) => console.error("Got error: ", error),
144+
clearError: () => setShowPasskeyConfirmationError(false),
145+
onError: () => setShowPasskeyConfirmationError(true),
146+
onFetchError: () => setShowPasskeyConfirmationError(true),
147+
onSuccess: (payload) => console.warn("payload: ", payload),
148+
setIsLoading: setIsLoading,
144149
});
145150
}, [callAPI]);
146151

@@ -151,6 +156,8 @@ export const SignUpForm = (
151156
{...props}
152157
email={continueClickResponse?.email || ""}
153158
onContinueClick={onConfirmationClick}
159+
errorMessageLabel={showPasskeyConfirmationError ? "WEBAUTHN_PASSKEY_RECOVERABLE_ERROR" : undefined}
160+
isLoading={isLoading}
154161
/>
155162
) : null;
156163
};

lib/ts/recipe/webauthn/components/themes/styles.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@
102102
margin-top: 9px;
103103
}
104104

105+
[data-supertokens~="passkeyConfirmationContainer"] [data-supertokens~="passkeyRecoverableErrorContainer"] {
106+
margin-top: 15px;
107+
border-radius: 6px;
108+
background-color: #fceaeb;
109+
color: #cf3644;
110+
padding: 10px;
111+
font-family: Arial;
112+
font-size: 14px;
113+
font-weight: 400;
114+
line-height: 16.59px;
115+
text-align: center;
116+
text-underline-position: from-font;
117+
text-decoration-skip-ink: none;
118+
}
119+
105120
[data-supertokens~="passkeyConfirmationContainer"] [data-supertokens~="passkeyConfirmationFooter"] {
106121
margin-top: 25px;
107122
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ export const defaultTranslationsWebauthn = {
1818
"Passkey will automatically be available across all your synced devices.",
1919
WEBAUTHN_FEATURE_BLOCK_KEEP_ACCOUNT_SAFER: "Keep your account safer",
2020
WEBAUTHN_FEATURE_BLOCK_KEEP_ACCOUNT_SAFER_DETAIL: "Passkey offer state of the art phishing resistance.",
21+
WEBAUTHN_PASSKEY_RECOVERABLE_ERROR:
22+
"The request either timed out, was canceled or the device is already registered. Please try again or try using another device.",
2123
},
2224
};

0 commit comments

Comments
 (0)