diff --git a/.changeset/rare-laws-stop.md b/.changeset/rare-laws-stop.md new file mode 100644 index 00000000000..3233a1342dd --- /dev/null +++ b/.changeset/rare-laws-stop.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +Improve `useCheckout` error messages on mount. diff --git a/packages/shared/src/react/hooks/useCheckout.ts b/packages/shared/src/react/hooks/useCheckout.ts index 64bd15b1f38..611ac309551 100644 --- a/packages/shared/src/react/hooks/useCheckout.ts +++ b/packages/shared/src/react/hooks/useCheckout.ts @@ -53,14 +53,18 @@ export const useCheckout = (options?: Params): __experimental_UseCheckoutReturn const clerk = useClerk(); const { organization } = useOrganization(); - const { user } = useUser(); + const { isLoaded, user } = useUser(); + + if (!isLoaded) { + throw new Error('Clerk: Ensure that `useCheckout` is inside a component wrapped with ``.'); + } if (!user) { - throw new Error('Clerk: User is not authenticated'); + throw new Error('Clerk: Ensure that `useCheckout` is inside a component wrapped with ``.'); } if (forOrganization === 'organization' && !organization) { - throw new Error('Clerk: Use `setActive` to set the organization'); + throw new Error('Clerk: Wrap your flow with a check for an active organization'); } const manager = useMemo(