Skip to content
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/puny-pants-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Throw error in development when opening `<Checkout />` without a session.
9 changes: 9 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,15 @@ export class Clerk implements ClerkInterface {
}
return;
}
if (noUserExists(this)) {
if (this.#instanceType === 'development') {
throw new ClerkRuntimeError(warnings.cannotOpenCheckout, {
code: CANNOT_RENDER_USER_MISSING_ERROR_CODE,
});
}
return;
}

void this.#componentControls
.ensureMounted({ preloadHint: 'Checkout' })
.then(controls => controls.openDrawer('checkout', props || {}));
Expand Down
2 changes: 2 additions & 0 deletions packages/clerk-js/src/core/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const warnings = {
cannotRenderAnyCommerceComponent: createMessageForDisabledCommerce,
cannotOpenUserProfile:
'The UserProfile modal cannot render unless a user is signed in. Since no user is signed in, this is no-op.',
cannotOpenCheckout:
'The Checkout drawer cannot render unless a user is signed in. Since no user is signed in, this is no-op.',
cannotOpenSignInOrSignUp:
'The SignIn or SignUp modals do not render when a user is already signed in, unless the application allows multiple sessions. Since a user is signed in and this application only allows a single session, this is no-op.',
};
Expand Down