Skip to content

fix(clerk-js): Show error message when account is locked #6336

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-garlics-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Adds missing error message when an account is locked in hash routing mode.
16 changes: 13 additions & 3 deletions packages/clerk-js/src/ui/elements/contexts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { ClerkAPIError, ClerkRuntimeError } from '@clerk/types';
import { FloatingTree, useFloatingParentNodeId } from '@floating-ui/react';
import React from 'react';

import { useRouter } from '@/ui/router';

import { useLocalizations } from '../../customizables';
import { useSafeState } from '../../hooks';

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

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

const [state, setState] = useSafeState<State>({
const [state, setState] = React.useState<State>(() => ({
status: 'idle',
metadata: undefined,
error: translateError(window?.Clerk?.__internal_last_error || undefined),
});
}));

React.useEffect(() => {
const error = window?.Clerk?.__internal_last_error;

if (error) {
setState(s => ({ ...s, error: translateError(error) }));
}
}, [translateError, setState, router.currentPath]);

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