Skip to content

Commit 51ce56d

Browse files
committed
feat(clerk-js): Send previous token and force_origin on /tokens requests
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.
1 parent 0b0f119 commit 51ce56d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/clerk-js/src/core/resources/Session.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,19 @@ export class Session extends BaseResource implements SessionResource {
480480
): Promise<TokenResource> {
481481
const path = template ? `${this.path()}/tokens/${template}` : `${this.path()}/tokens`;
482482
// TODO: update template endpoint to accept organizationId
483-
const params: Record<string, string | null> = template ? {} : { organizationId: organizationId ?? null };
483+
const params: Record<string, string | null> = template
484+
? {}
485+
: {
486+
organizationId: organizationId ?? null,
487+
...(this.lastActiveToken ? { token: this.lastActiveToken.getRawString() } : {}),
488+
};
484489
const lastActiveToken = this.lastActiveToken?.getRawString();
485490

486-
const tokenResolver = Token.create(path, params, skipCache ? { debug: 'skip_cache' } : undefined).catch(e => {
491+
const tokenResolver = Token.create(
492+
path,
493+
params,
494+
skipCache ? { debug: 'skip_cache', force_origin: 'true' } : undefined,
495+
).catch(e => {
487496
if (MissingExpiredTokenError.is(e) && lastActiveToken) {
488497
return Token.create(path, { ...params }, { expired_token: lastActiveToken });
489498
}

0 commit comments

Comments
 (0)