Skip to content

feat(clerk-js): Send previous token and force_origin on /tokens requests#8096

Closed
nikosdouvlis wants to merge 3 commits intomainfrom
nikos/plat-2566-session-minter-sdk-params
Closed

feat(clerk-js): Send previous token and force_origin on /tokens requests#8096
nikosdouvlis wants to merge 3 commits intomainfrom
nikos/plat-2566-session-minter-sdk-params

Conversation

@nikosdouvlis
Copy link
Member

Why

Session Minter needs the previous session JWT to clone claims at the edge without hitting the DB. It also needs a way for skipCache callers to bypass the edge minter and go straight to origin.

What

  • Add oiat (original_issued_at) to JwtHeader type, marked @internal. Session Minter uses this to track when claims were last assembled from the DB. Lives in the JWT header, not payload.
  • Send token (previous session JWT) in the POST body on non-template /tokens requests. Uses conditional spread so the key is absent (not token=) when there's no previous token.
  • Send force_origin=true in the query string when skipCache: true. Tells FAPI Proxy to route to origin instead of Session Minter.

Both params are currently ignored by the backend and will be wired up in PLAT-2471 and PLAT-2472.

Test plan

  • Verify token appears in POST body when a previous token exists
  • Verify token key is absent on first mint (no previous token)
  • Verify token is not sent for template token requests
  • Verify force_origin=true in query string when skipCache: true
  • Verify force_origin absent when skipCache: false
  • Existing token refresh flows still work (no behavioral change yet)

Session Minter needs an oiat (original_issued_at) field in the JWT
header to track when token claims were last assembled from the DB.
This enables monotonic freshness checks that prevent edge-minted
tokens with stale claims from overwriting fresher ones.

Marked @internal so developers don't depend on this field.
Two changes to Session.#createTokenResolver():

1. Send the current session JWT as `token` in the POST body on
   non-template /tokens requests. This lets the FAPI Proxy forward it
   to Session Minter for claim cloning without a DB read.

2. Send `force_origin=true` in the query string when skipCache is true.
   This tells the FAPI Proxy to route directly to origin instead of
   Session Minter, preserving the skipCache contract of always returning
   authoritative DB-minted tokens.
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 18, 2026 10:00am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: 0adfe52

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@clerk/shared Patch
@clerk/clerk-js Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch

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

@nikosdouvlis
Copy link
Member Author

Split into #8105 (send token) and #8106 (force_origin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant