Auth0 middleware sets cookie and reloads page.tsx on every Server Action call

Open
#2,124 9 comments 8 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@sleitor is already working on this.

Since Sep 2, 2026.

  • #2833 by @sleitor — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet

Research direction

Start in src/server/auth-client.ts at the middleware request path, then inspect stateless-session-store.ts and stateful-session-store.ts for cookie updates. Reproduce the Server Action flow in the nextjs-auth0 Sample-01 app with a Next-Action header. Done means Server Action calls no longer trigger unnecessary cookie updates or RSC reloads while normal session handling remains intact.

Written by the indexing model from the issue text.

Description

ack bug V4
Checklist
Description

Auth0 middleware sets cookies and triggers page reloads on every Server Action call

Cause
  • Next.js revalidates Router Cache when cookies are updated in Server Actions Next.js Deep Dive: Caching
  • auth0-nextjs works as follows on requests to Server Action when processed by middleware: auth-client.js
  1. Retrieve the session from the sessionStore
  2. If session can be retrieved, update sessionStore for rolling update
    a. For the default StatelessSessionStore, encrypt the originalSessionData in the session into jwe, chunk it, and store it in the cookie. In jwe, the cookie is updated each time because it includes the time of creation: stateless-session-store.ts
    b. For StatefulSessionStore, session ID is chunked into jwe and stored in cookie. jwe includes generation time, so cookie is updated every time stateful-session-store.ts
Reproduction
Assumption
  • In middleware, set up a call to auth0.middleware
  • Reproduce with or without sessionStore set in Auth0 configuration
Reproduction
  1. Call Server Action
  2. Because auth0.middleware performs authentication processing, a Set-Cookie is added to the response header, X-Action-Revalidated becomes [[],0,1], and NextJS Client follows the instructions to reload RSC (React Server Component) reloading the RSC (React Server Component) as instructed.

https://github.com/user-attachments/assets/424448d5-43c0-4033-95a0-3e9796441c37

Additional context

When server action call, please skip to update cookie. We can identify server action when the request has Next-Action header.

Or if session.rolling is false, skip cookie update process and manage cookie lifetime based on the first cookie created. This TODO comment suggests this behavior

nextjs-auth0 version

4.6.0

Next.js version

15.3.2

Node.js version

22.10

Dominant language
TypeScript
Stars
2.3k
Forks
472
Avg merge
1d 14h
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from auth0/nextjs-auth0

All issues in auth0/nextjs-auth0

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.