Skip to content

Commit 61b592e

Browse files
authored
fix(clerk-js): Show error message when account is locked (#6336)
1 parent 91470b9 commit 61b592e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.changeset/soft-garlics-wonder.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+
Adds missing error message when an account is locked in hash routing mode.

packages/clerk-js/src/ui/elements/contexts/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import type { ClerkAPIError, ClerkRuntimeError } from '@clerk/types';
33
import { FloatingTree, useFloatingParentNodeId } from '@floating-ui/react';
44
import React from 'react';
55

6+
import { useRouter } from '@/ui/router';
7+
68
import { useLocalizations } from '../../customizables';
7-
import { useSafeState } from '../../hooks';
89

910
type Status = 'idle' | 'loading' | 'error';
1011
type Metadata = string | undefined;
@@ -18,12 +19,21 @@ const [CardStateCtx, _useCardState] = createContextAndHook<CardStateCtxValue>('C
1819

1920
export const CardStateProvider = (props: React.PropsWithChildren<any>) => {
2021
const { translateError } = useLocalizations();
22+
const router = useRouter();
2123

22-
const [state, setState] = useSafeState<State>({
24+
const [state, setState] = React.useState<State>(() => ({
2325
status: 'idle',
2426
metadata: undefined,
2527
error: translateError(window?.Clerk?.__internal_last_error || undefined),
26-
});
28+
}));
29+
30+
React.useEffect(() => {
31+
const error = window?.Clerk?.__internal_last_error;
32+
33+
if (error) {
34+
setState(s => ({ ...s, error: translateError(error) }));
35+
}
36+
}, [translateError, setState, router.currentPath]);
2737

2838
const value = React.useMemo(() => ({ value: { state, setState } }), [state, setState]);
2939
return <CardStateCtx.Provider value={value}>{props.children}</CardStateCtx.Provider>;

0 commit comments

Comments
 (0)