chore(tanstack-react-start,nuxt): Pass treatPendingAsSignedOut to auth functions#6612
chore(tanstack-react-start,nuxt): Pass treatPendingAsSignedOut to auth functions#6612wobsoriano merged 6 commits intomainfrom
treatPendingAsSignedOut to auth functions#6612Conversation
🦋 Changeset detectedLatest commit: 1b12269 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds per-call auth options (PendingSessionOptions) to Nuxt and TanStack React Start server code. Nuxt middleware refactors auth object retrieval into an authObjectFn(opts) that calls requestState.toAuth(opts); the Proxy and initial client state now read from this function and token acceptance is determined per-call. Types changed to use PendingSessionOptions & Pick<AuthenticateRequestOptions, 'acceptsToken'>. getAuth and event.context.auth signatures now accept an optional options parameter (including treatPendingAsSignedOut). Import lists updated where needed and public API shapes remain compatible. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/nuxt/src/runtime/server/clerkMiddleware.ts (1)
117-125: Bug: Proxygettrap indexes the function type instead of the auth object
return authObjectFn()?.[prop as keyof typeof authObjectFn];treatsauthObjectFn(a function) as the indexed target. This is a TypeScript typing mistake and can also be fragile at runtime for symbol keys. Forward to the actual auth object viaReflect.get.Apply this diff:
const auth = new Proxy(authHandler, { get(target, prop, receiver) { deprecated('event.context.auth', 'Use `event.context.auth()` as a function instead.'); // If the property exists on the function, return it if (prop in target) return Reflect.get(target, prop, receiver); - // Otherwise, get it from the authObject - return authObjectFn()?.[prop as keyof typeof authObjectFn]; + // Otherwise, forward the property access to the current auth object + const authObject = authObjectFn(); + return Reflect.get(authObject as unknown as Record<PropertyKey, unknown>, prop, receiver); }, });
🧹 Nitpick comments (6)
packages/tanstack-react-start/src/server/getAuth.ts (3)
11-21: Signature and Request guard look fine; clarify intent in JSDocThe function keeps the legacy
(request, opts?)signature, only usingrequestfor presence checks while sourcing the auth object from context. Add a short JSDoc note thatrequestis only validated (not consumed) to avoid confusion for integrators.
22-24: Forward only pending-session options toauthObjectFn(future-proofing)Right now you pass
{ treatPendingAsSignedOut }. IfPendingSessionOptionsgrows, the current code will need changes. Slightly generalize while still excludingacceptsToken:- const authObject = await Promise.resolve(authObjectFn({ treatPendingAsSignedOut: opts?.treatPendingAsSignedOut })); + const pendingOptions = opts ? { treatPendingAsSignedOut: opts.treatPendingAsSignedOut } : undefined; + const authObject = await Promise.resolve(authObjectFn(pendingOptions));
25-26: Default behavior foracceptsTokenshould be documentedYou pass
opts?.acceptsTokenthrough togetAuthObjectForAcceptedToken. Please document in the JSDoc what happens whenacceptsTokenis omitted (i.e., the default behavior), so callers know when to supply it explicitly.I can add the JSDoc to this function and align it with the Nuxt middleware docs—want me to push a follow-up?
packages/nuxt/src/runtime/server/clerkMiddleware.ts (1)
112-130: Add examples and deprecation note to public docsSince
event.context.authnow prefers function calls and supports per-call pending-session options, please update the Nuxt docs/JSDoc:
- Show
event.context.auth({ treatPendingAsSignedOut: false }).- Clarify that property access is deprecated and will log a warning.
I can draft the JSDoc snippet for this file and
types.tsif helpful.packages/nuxt/src/runtime/server/types.ts (1)
16-46: Overloads updated correctly; add JSDoc forPendingSessionOptionsThe final overload
(options?: PendingSessionOptions): SessionAuthObjectaligns with the new per-call semantics. Augment the examples to include:
event.context.auth({ treatPendingAsSignedOut: false })- Clarify default:
treatPendingAsSignedOutdefaults totrue.This will help consumers rely on type hints and examples.
I can add the JSDoc blocks with examples and defaults inline here.
packages/tanstack-react-start/src/server/middlewareHandler.ts (1)
28-35: Note on accepted tokens: limit to pending-session options by designUnlike Nuxt, TanStack’s
event.context.authintentionally accepts onlyPendingSessionOptions. Filtering by token type is handled ingetAuth()viagetAuthObjectForAcceptedToken. Consider a short comment in this file to make that design explicit for maintainers.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
packages/nuxt/src/runtime/server/clerkMiddleware.ts(3 hunks)packages/nuxt/src/runtime/server/types.ts(2 hunks)packages/tanstack-react-start/src/server/getAuth.ts(2 hunks)packages/tanstack-react-start/src/server/middlewareHandler.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
**/*
⚙️ CodeRabbit configuration file
If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.
Files:
packages/nuxt/src/runtime/server/types.tspackages/tanstack-react-start/src/server/middlewareHandler.tspackages/nuxt/src/runtime/server/clerkMiddleware.tspackages/tanstack-react-start/src/server/getAuth.ts
🧬 Code graph analysis (4)
packages/nuxt/src/runtime/server/types.ts (1)
packages/types/src/session.ts (1)
PendingSessionOptions(34-40)
packages/tanstack-react-start/src/server/middlewareHandler.ts (1)
packages/types/src/session.ts (1)
PendingSessionOptions(34-40)
packages/nuxt/src/runtime/server/clerkMiddleware.ts (4)
packages/types/src/session.ts (1)
PendingSessionOptions(34-40)packages/nuxt/src/runtime/server/types.ts (2)
AuthFn(16-46)AuthOptions(11-11)integration/templates/nuxt-node/server/api/me.js (1)
event(4-4)packages/nuxt/src/runtime/server/utils.ts (1)
createInitialState(20-23)
packages/tanstack-react-start/src/server/getAuth.ts (3)
packages/nextjs/src/server/createGetAuth.ts (1)
GetAuthOptions(18-20)packages/types/src/session.ts (1)
PendingSessionOptions(34-40)packages/backend/src/tokens/types.ts (1)
AuthenticateRequestOptions(19-75)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (22)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (22, **)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (6)
packages/tanstack-react-start/src/server/getAuth.ts (1)
9-9: Type alias aligns with cross-package conventionUsing
PendingSessionOptions & Pick<AuthenticateRequestOptions, 'acceptsToken'>matches the shape used in other packages and keeps the surface consistent.packages/nuxt/src/runtime/server/clerkMiddleware.ts (3)
112-116: Per-call pending-session handling is correctly wired
authObjectFn(opts)returningrequestState.toAuth(opts)and delegating togetAuthObjectForAcceptedTokeninsideauthHandlergive you the desired per-call behavior without mutating shared state.
129-130: Initial state built fromauthObjectFn()looks goodSeeding
__clerk_initial_statefrom a fresh auth object ensures it reflects the defaulttreatPendingAsSignedOutbehavior for clients.
112-125: No remaining deprecatedevent.context.authproperty‐style usages foundA repository‐wide search (over *.ts, *.tsx, *.js, *.jsx) for
event.context.authnot followed by()and for direct property accesses (e.g..userId,.orgId,.sessionId,.actor,.claims) returned no occurrences beyond the middleware setup itself. No consumer code uses the deprecated property style, so no migration is needed. I’m resolving this comment.packages/nuxt/src/runtime/server/types.ts (1)
11-11: Type shape matches other frameworks
AuthOptions = PendingSessionOptions & Pick<AuthenticateRequestOptions, 'acceptsToken'>mirrors the shape used in Next/TanStack and enables consistent per-call options.packages/tanstack-react-start/src/server/middlewareHandler.ts (1)
33-35: TanStackevent.context.auth(options?)forwarding is correctAllowing
(options?: PendingSessionOptions)and forwarding torequestState.toAuth(options)brings parity with Nuxt/Next behavior. No other changes needed here.
treatPendingAsSignedOut to toAuth()treatPendingAsSignedOut to auth functions
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
.changeset/ninety-wombats-think.md (3)
6-7: Add one-line context on what the option does.A brief explanation will help readers scanning release notes understand “why” without opening the code.
-Allows passing of `treatPendingAsSignedOut` to auth functions: +Allows passing of `treatPendingAsSignedOut` to auth functions (treats a pending session the same as a signed-out state when evaluating auth):
8-9: Use the package’s proper name in the heading.The package is
@clerk/tanstack-react-start. Consider reflecting that to avoid confusion with other TanStack runtimes.-TanStack Start +TanStack React Start
20-26: Confirm whetherevent.context.auth(...)is synchronous in Nuxt.If
event.context.authreturns a plain object (sync), the snippet is fine; if it’s async (returns a Promise), useawait. Align with the actual return type to prevent copy/paste errors.For async:
export default eventHandler(async (event) => { const { userId } = await event.context.auth({ treatPendingAsSignedOut: true }); return { userId }; });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
.changeset/ninety-wombats-think.md(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/ninety-wombats-think.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep/ci
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
.changeset/ninety-wombats-think.md (2)
1-4: Changeset front matter looks valid.Package scopes and bump type (patch) are correct for a non-breaking option pass-through. No issues here.
10-17: VerifiedgetAuthsignature—example is correct.The
getAuthAPI across all packages (includingtanstack-react-start,remix,react-router,fastify, andexpress) is defined asgetAuth(request, opts?). There are no usages of a single-argument signature (getAuth(opts)), and all existing call sites pass both the request (or loader args) and an options object. The snippet in.changeset/ninety-wombats-think.mdis therefore accurate and needs no adjustment.
.changeset/ninety-wombats-think.md
Outdated
| "@clerk/tanstack-react-start": patch | ||
| --- | ||
|
|
||
| Allows passing of `treatPendingAsSignedOut` to auth functions: |
There was a problem hiding this comment.
We can link to our docs that give more information around treatPendingAsSignedOut: https://clerk.com/docs/authentication/configuration/session-tasks#session-handling
.changeset/ninety-wombats-think.md
Outdated
| ```ts | ||
| const authStateFn = createServerFn({ method: 'GET' }).handler(async () => { | ||
| const request = getWebRequest() | ||
| const { userId } = await getAuth(request, { treatPendingAsSignedOut: true }) |
There was a problem hiding this comment.
treatPendingAsSignedOut: true is already the default, so we could pass treatPendingAsSignedOut: false here
// Both `active` and `pending` sessions will be treated as authenticated when `treatPendingAsSignedOut` is `false` - `userId` will be returned
return { userId }
Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Improvements
Compatibility