-
Notifications
You must be signed in to change notification settings - Fork 265
React Vanilla Sample App Improvements for Passkey #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -313,6 +313,15 @@ const LoginPage = () => { | |||||||
| setRegOnlySuccess(true); | ||||||||
| } | ||||||||
| } else if (data.type === "VIEW") { | ||||||||
| // Check for passkey creation options in additionalData - check this first | ||||||||
| if (data.data?.additionalData?.passkeyCreationOptions) { | ||||||||
| setPasskeyCreationOptions(data.data.additionalData.passkeyCreationOptions); | ||||||||
| } | ||||||||
| // Check for passkey authentication challenge in additionalData - check this first | ||||||||
| if (data.data?.additionalData?.passkeyChallenge) { | ||||||||
| setPasskeyChallenge(data.data.additionalData.passkeyChallenge); | ||||||||
| } | ||||||||
|
|
||||||||
| // Handle the VIEW response | ||||||||
| // Check if this is an input prompt (has inputs to collect) | ||||||||
| if (data.data?.inputs && data.data.inputs.length > 0) { | ||||||||
|
|
@@ -325,14 +334,6 @@ const LoginPage = () => { | |||||||
| if (data.data?.actions) { | ||||||||
| setAvailableActions(data.data.actions); | ||||||||
| } | ||||||||
| // Check for passkey creation options in additionalData | ||||||||
| if (data.data?.additionalData?.passkeyCreationOptions) { | ||||||||
| setPasskeyCreationOptions(data.data.additionalData.passkeyCreationOptions); | ||||||||
| } | ||||||||
| // Check for passkey authentication challenge in additionalData | ||||||||
| if (data.data?.additionalData?.passkeyChallenge) { | ||||||||
| setPasskeyChallenge(data.data.additionalData.passkeyChallenge); | ||||||||
| } | ||||||||
| } else if (data.data?.actions && data.data.actions.length > 1) { | ||||||||
| // This is a decision screen - multiple actions to choose from | ||||||||
| setNeedsDecision(true); | ||||||||
|
|
@@ -404,6 +405,8 @@ const LoginPage = () => { | |||||||
| setRedirectURL(null); | ||||||||
| setSocialIdpName(''); | ||||||||
| setRegOnlySuccess(false); | ||||||||
| setPasskeyCreationOptions(null); | ||||||||
| setPasskeyChallenge(null); | ||||||||
|
|
||||||||
| initiateNativeAuthFlow(isSignupMode ? 'REGISTRATION' : 'LOGIN') | ||||||||
| .then((result) => { | ||||||||
|
|
@@ -419,6 +422,15 @@ const LoginPage = () => { | |||||||
| setError(true); | ||||||||
| setErrorMessage(data.failureReason || defaultMessage); | ||||||||
| } else if (data.type === "VIEW") { | ||||||||
| // Check for passkey creation options in additionalData - check this first | ||||||||
| if (data.data?.additionalData?.passkeyCreationOptions) { | ||||||||
| setPasskeyCreationOptions(data.data.additionalData.passkeyCreationOptions); | ||||||||
| } | ||||||||
| // Check for passkey authentication challenge in additionalData - check this first | ||||||||
| if (data.data?.additionalData?.passkeyChallenge) { | ||||||||
| setPasskeyChallenge(data.data.additionalData.passkeyChallenge); | ||||||||
| } | ||||||||
|
|
||||||||
| // Handle the VIEW response | ||||||||
| // Check if this is an input prompt (has inputs to collect) | ||||||||
| if (data.data?.inputs && data.data.inputs.length > 0) { | ||||||||
|
|
@@ -483,6 +495,8 @@ const LoginPage = () => { | |||||||
| setSocialIdpName(''); | ||||||||
| setRegOnlySuccess(false); | ||||||||
| setPromptRegistration(false); | ||||||||
| setPasskeyCreationOptions(null); | ||||||||
| setPasskeyChallenge(null); | ||||||||
|
|
||||||||
| // Ensure all input fields are present in formData, even if empty | ||||||||
| const completeFormData = { ...formData }; | ||||||||
|
|
@@ -504,6 +518,15 @@ const LoginPage = () => { | |||||||
| setError(true); | ||||||||
| setErrorMessage(data.failureReason || 'Registration failed. Please check your information.'); | ||||||||
| } else if (data.type === "VIEW") { | ||||||||
| // Check for passkey creation options in additionalData - check this first | ||||||||
| if (data.data?.additionalData?.passkeyCreationOptions) { | ||||||||
| setPasskeyCreationOptions(data.data.additionalData.passkeyCreationOptions); | ||||||||
| } | ||||||||
| // Check for passkey authentication challenge in additionalData - check this first | ||||||||
| if (data.data?.additionalData?.passkeyChallenge) { | ||||||||
| setPasskeyChallenge(data.data.additionalData.passkeyChallenge); | ||||||||
| } | ||||||||
|
|
||||||||
| // Handle the VIEW response | ||||||||
| // Check if this is an input prompt (has inputs to collect) | ||||||||
| if (data.data?.inputs && data.data.inputs.length > 0) { | ||||||||
|
|
@@ -634,6 +657,9 @@ const LoginPage = () => { | |||||||
| }) | ||||||||
| .catch((error) => { | ||||||||
| console.error("Error submitting passkey credential:", error); | ||||||||
| setConnectionError(false); | ||||||||
| setNeedsDecision(false); | ||||||||
| setAvailableActions([]); | ||||||||
| handleSubmissionError(error); | ||||||||
| }); | ||||||||
| }; | ||||||||
|
|
@@ -667,6 +693,11 @@ const LoginPage = () => { | |||||||
| }) | ||||||||
| .catch((error) => { | ||||||||
| console.error("Error submitting passkey assertion:", error); | ||||||||
| setNeedsDecision(false); | ||||||||
| setAvailableActions([]); | ||||||||
| setSelectedAction(null); | ||||||||
| setFormData({}); | ||||||||
| setInputs([]); | ||||||||
|
||||||||
| setInputs([]); | |
| setInputs([]); | |
| setConnectionError(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling for passkey credential submission (lines 660-662) clears fewer state variables compared to the passkey assertion error handler (lines 696-700). For consistency and to ensure a clean UI state on errors, consider also clearing
setSelectedAction(null),setFormData({}), andsetInputs([])in this error handler, similar to the passkey assertion error handler.