With frontendApiProxy enabled, the first API request after sign-in returns signed-out (client-uat-but-no-session-token)

Aberta
#10,790 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@ShivamJuyal24 já está trabalhando nisso.

Desde 14/11/2026.

Avaliação

Dificuldade
3/5
Tempo estimado
Meio dia
Facilidade para iniciantes
62/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
nextjs, nodejs, typescript

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Title: With frontendApiProxy enabled, the first API request after sign-in returns signed-out (client-uat-but-no-session-token)

Packages
  • @clerk/nextjs 7.2.5 (@clerk/backend 3.3.0)
  • The same code is in @clerk/backend 3.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
  1. Sign in with Google OAuth (via /sso-callback and AuthenticateWithRedirectCallback).
  2. The app navigates client-side to a protected page, which calls fetch("/api/projects").
  3. That request gets a 401: the middleware's auth() returns userId: null.
  4. 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.

Linguagem predominante
TypeScript
Estrelas
1.8k
Forks
492
Merge médio
1d 7h
PRs com merge (30d)
357

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de clerk/javascript

Todas as issues de clerk/javascript

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.