With frontendApiProxy enabled, the first API request after sign-in returns signed-out (client-uat-but-no-session-token)
維護者通常 1 天內回覆
@ShivamJuyal24 已經在處理了。
開始於 2026年11月14日。
評估
- 難度
- 3/5
- 預估耗時
- 半天
- 新手友好度
- 62/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- nextjs, nodejs, typescript
研究方向
Start in the backend package's AuthenticateContext: read usesSuffixedCookies() and tokenBelongsToInstance(), and compare the token issuer against originalFrontendApi and the proxy URL the issue describes. Reproduce with a non-document request carrying __client_uat and __session without a suffix, using a proxy-configured clerkMiddleware. Done when such a request resolves as signed in and the existing suffixed-cookie tests still pass.
由索引模型根據 Issue 內容生成。
描述
Title: With frontendApiProxy enabled, the first API request after sign-in returns signed-out (client-uat-but-no-session-token)
Packages
@clerk/nextjs7.2.5 (@clerk/backend3.3.0)- The same code is in
@clerk/backend3.27.0 (latest at the time of writing) - Production instance, Next.js 16 App Router, deployed on Vercel
Setup
clerkMiddleware(handler, { frontendApiProxy: { enabled: true, path: "/__clerk" } })NEXT_PUBLIC_CLERK_PROXY_URL=https://<our-domain>/__clerk- The proxy is enabled in the Clerk dashboard with the same URL
- The publishable key's Frontend API is
clerk.<our-domain>
What happens
- Sign in with Google OAuth (via
/sso-callbackandAuthenticateWithRedirectCallback). - The app navigates client-side to a protected page, which calls
fetch("/api/projects"). - That request gets a 401: the middleware's
auth()returnsuserId: null. - A hard refresh fixes it: the document request goes through a handshake, and after that every request works.
It happens on every sign-in, in a fresh browser too.
Cookies on the failing request
__client_uat=1794509021
__client_uat_<suffix>=1794509017
__session=<JWT: iss="https://<our-domain>/__clerk", azp="https://<our-domain>", iat=1794509021>
(no __session_<suffix>)
Cause, from reading the source
AuthenticateContext.usesSuffixedCookies() returns true early when the plain session token does not belong to the instance:
if (session && !this.tokenBelongsToInstance(session)) {
return true;
}
tokenBelongsToInstance() compares the token's iss, without its scheme, against this.originalFrontendApi. That value comes from the publishable key (clerk.<our-domain>). With a proxy, the issuer is <our-domain>/__clerk, so the check fails for every token this instance issues.
The context then reads the suffixed cookies. Right after sign-in, __client_uat_<suffix> is set but __session_<suffix> is not, so the request resolves to client-uat-but-no-session-token. A non-document request can't run a handshake, so it is treated as signed out.
Expected
A token whose issuer is the configured proxy URL counts as belonging to the instance, and the plain cookies are used as they are without a proxy.
Possible fix
In tokenBelongsToInstance, also accept the proxy URL (this.proxyUrl without its scheme) as an issuer for this instance.
Workaround
Turn the proxy off.
- 主要語言
- TypeScript
- 星號
- 1.8k
- 分支
- 492
- 平均合併
- 1 天 7 小時
- 30 天內合併 PR
- 357
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
clerk/javascript 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 85/100
clerk/javascript#10708 ·
維護者通常 1 天內回覆
-
Built-in reverification dialog lacks an accessible name (aria-dialog-name)可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
clerk/javascript#10548 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
clerk/javascript#10547 ·
維護者通常 1 天內回覆
-
<SignIn />: first "Use email" click switches back to phone when `initialValues.phoneNumber` is set可能已有人在做 @twicestruck 於 20 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 74/100
clerk/javascript#10487 ·
維護者通常 1 天內回覆
-
useLoadedIsomorphicClerk misses "ready" when a ClerkProvider remounts after clerk-js has loaded — <ClerkLoading> never resolves可能重新可做 關聯的 PR 已關閉且未合併。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
clerk/javascript#10462 ·
維護者通常 1 天內回覆
相似的 Issue
-
Type/Improvement
難度 2/5 1-3 小時 新手友好度 67/100
OpenNSW/nsw-srilanka#1259 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
oxc-project/tsrs#1010 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
Fission-AI/OpenSpec#2260 ·
維護者通常 1 天內回覆
-
Add: ESP 1 UK未關閉check:passed streams:add
難度 1/5 1-3 小時 新手友好度 64/100
維護者通常 1 天內回覆
-
area:infra area:storage bug
難度 2/5 1-3 小時 新手友好度 76/100
THU-MAIC/OpenMAIC#2311 · 1 則留言 ·
維護者通常 1 天內回覆