Auth0 middleware sets cookie and reloads page.tsx on every Server Action call
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- nextjs, react, typescript
- Domain
- authentication, backend-api-design
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
Checklist
- The issue can be reproduced in the nextjs-auth0 sample app (or N/A).
- I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- I have looked into the API documentation and have not found a suitable solution or answer.
- I have searched the issues and have not found a suitable solution or answer.
- I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- I agree to the terms within the Auth0 Code of Conduct.
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
- Retrieve the session from the sessionStore
- 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
- Call Server Action
- 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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from auth0/nextjs-auth0
-
ack
Difficulty 4/5 3-5 days Newbie friendliness 38/100
auth0/nextjs-auth0#2463 · 9 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
v4: First class support to handle a Refresh Token rotation failureMay be free again @tusharpandey13 claimed this 555 days ago, and no pull request is open. Openack Feature Request V4
auth0/nextjs-auth0#2036 · 3 comments · 5 reactions · 1 assignee ·
Maintainers usually reply within 1 day
All issues in auth0/nextjs-auth0
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
milind-soni/OpenMausBot#6730 ·
Maintainers usually reply within 1 day
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Openarea: @angular/build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
angular/angular-cli#34764 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30384 · 1 comment ·
Maintainers usually reply within 1 day
-
P2
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day