feat(*): Make useAuth().getToken() throw during SSR#7730
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 678b5e5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThe changes implement SSR-safety for the useAuth().getToken function across multiple Clerk React packages. A browser environment check is added to throw a ClerkRuntimeError when getToken is invoked in non-browser contexts. The changelog documents breaking version changes and migration guidance, including updated error messages that provide reference documentation for server-side auth access. Tests verify the error-throwing behavior. JSDoc comments are expanded to document the throw contract and server-side access patterns. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
|
!allow-major |
Description
The uSES PR removed the
useAuthwrapper from thenextjspackage. That wrapper madegetTokenbeundefinedin server environments, and removing that caused callinguseAuth().getToken()to stall forever during server-side rendering.This PR tackles this at the
reactpackage level instead, since it's a common concern. During server-side rendering,getTokenis now a function that throws aclerk_runtime_not_browsererror.The error aligns with this PR: Make gettoken callable outside of react
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Breaking Changes
useAuth().getTokennow throws an error in non-browser environments instead of returning undefined. Wrap calls in try/catch or use only within browser contexts (useEffect, event handlers, or non-suspenseful data fetching). Server-side token access requires using the Auth object instead.Documentation