Skip to content

Commit d30d566

Browse files
authored
fix(clerk-js): Guard against navigation during setActive in SignInFactorOne (#6462)
1 parent c8d4c20 commit d30d566

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.changeset/eager-cats-attend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Guard against navigation to root sign-in route during `setActive` in `SignInFactorOne`

packages/clerk-js/src/ui/components/SignIn/SignInFactorOne.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useClerk } from '@clerk/shared/react';
12
import type { SignInFactor } from '@clerk/types';
23
import React from 'react';
34

@@ -39,6 +40,7 @@ const factorKey = (factor: SignInFactor | null | undefined) => {
3940
};
4041

4142
function SignInFactorOneInternal(): JSX.Element {
43+
const { __internal_setActiveInProgress } = useClerk();
4244
const signIn = useCoreSignIn();
4345
const { preferredSignInStrategy } = useEnvironment().displayConfig;
4446
const availableFactors = signIn.supportedFirstFactors;
@@ -83,21 +85,27 @@ function SignInFactorOneInternal(): JSX.Element {
8385
const [isPasswordPwned, setIsPasswordPwned] = React.useState(false);
8486

8587
React.useEffect(() => {
88+
if (__internal_setActiveInProgress) {
89+
return;
90+
}
91+
8692
// Handle the case where a user lands on alternative methods screen,
8793
// clicks a social button but then navigates back to sign in.
8894
// SignIn status resets to 'needs_identifier'
8995
if (signIn.status === 'needs_identifier' || signIn.status === null) {
9096
void router.navigate('../');
9197
}
92-
}, []);
98+
}, [__internal_setActiveInProgress]);
9399

94-
if (!currentFactor && signIn.status) {
95-
return (
100+
if (!currentFactor) {
101+
return signIn.status ? (
96102
<ErrorCard
97103
cardTitle={localizationKeys('signIn.noAvailableMethods.title')}
98104
cardSubtitle={localizationKeys('signIn.noAvailableMethods.subtitle')}
99105
message={localizationKeys('signIn.noAvailableMethods.message')}
100106
/>
107+
) : (
108+
<LoadingCard />
101109
);
102110
}
103111

0 commit comments

Comments
 (0)