Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elements): Verification form not submitting after returning from ChooseStrategy without a selection #3425

Merged
merged 8 commits into from
May 23, 2024
6 changes: 6 additions & 0 deletions .changeset/red-gorillas-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/elements': patch
---

Fix: Verification form submission wasn't working after returning from "choosing an alternate strategy" without making a selection.
Perf: Adds a `NeverRetriable` state for applicable strategies so the countdown doesn't run needlessly.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ export const SignInRouterMachine = setup({
ChoosingStrategy: {
tags: ['route:choose-strategy'],
on: {
'NAVIGATE.PREVIOUS': 'Idle',
'NAVIGATE.PREVIOUS': {
description: 'Go to Idle, and also tell firstFactor to go to Pending',
target: 'Idle',
actions: sendTo('firstFactor', { type: 'NAVIGATE.PREVIOUS' }),
},
},
},
ForgotPassword: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const SignInVerificationMachine = setup({
},
guards: {
isResendable: ({ context }) => context.resendable || context.resendableAfter === 0,
isNeverResendable: ({ context }) => context.currentFactor?.strategy === 'password',
Copy link
Member

@LekoArts LekoArts May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there more strategies that are never resendable?
For example: passkey, google_one_tap, saml

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are, though I wasn't looking to address each of them in this PR. Especially, as passkey and google_one_tap haven't been integrated yet. While retaining the other flow isn't ideal, it doesn't cause any issues either.

},
delays: SignInVerificationDelays,
types: {} as SignInVerificationSchema,
Expand All @@ -161,6 +162,7 @@ const SignInVerificationMachine = setup({
}),
initial: 'Init',
on: {
'NAVIGATE.PREVIOUS': '.Hist',
'STRATEGY.REGISTER': {
actions: assign({
registeredStrategies: ({ context, event }) => context.registeredStrategies.add(event.factor),
Expand Down Expand Up @@ -233,11 +235,31 @@ const SignInVerificationMachine = setup({
reenter: true,
},
},
initial: 'NotResendable',
initial: 'Init',
states: {
Init: {
description: 'Marks appropriate factors as never resendable.',
always: [
{
guard: 'isNeverResendable',
target: 'NeverResendable',
},
{
target: 'NotResendable',
},
],
},
Resendable: {
description: 'Waiting for user to retry',
},
NeverResendable: {
description: 'Handles never resendable',
on: {
RETRY: {
actions: log('Never retriable'),
},
},
},
NotResendable: {
description: 'Handle countdowns',
on: {
Expand Down Expand Up @@ -299,6 +321,9 @@ const SignInVerificationMachine = setup({
},
},
},
Hist: {
type: 'history',
},
},
});

Expand Down
Loading