Skip to content

Commit ef87617

Browse files
authored
chore(shared): Improve useCheckout error messages (#6475)
1 parent e3d073e commit ef87617

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/rare-laws-stop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/shared': patch
3+
---
4+
5+
Improve `useCheckout` error messages on mount.

packages/shared/src/react/hooks/useCheckout.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ export const useCheckout = (options?: Params): __experimental_UseCheckoutReturn
5353

5454
const clerk = useClerk();
5555
const { organization } = useOrganization();
56-
const { user } = useUser();
56+
const { isLoaded, user } = useUser();
57+
58+
if (!isLoaded) {
59+
throw new Error('Clerk: Ensure that `useCheckout` is inside a component wrapped with `<ClerkLoaded />`.');
60+
}
5761

5862
if (!user) {
59-
throw new Error('Clerk: User is not authenticated');
63+
throw new Error('Clerk: Ensure that `useCheckout` is inside a component wrapped with `<SignedIn />`.');
6064
}
6165

6266
if (forOrganization === 'organization' && !organization) {
63-
throw new Error('Clerk: Use `setActive` to set the organization');
67+
throw new Error('Clerk: Wrap your flow with a check for an active organization');
6468
}
6569

6670
const manager = useMemo(

0 commit comments

Comments
 (0)