nextauthjs / nextauthjs/next-auth
Lazy Initialization does not work in middleware
Open
Nobody has claimed this yet.
bug
triage
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
System:
OS: macOS 15.4.1
CPU: (8) arm64 Apple M1 Pro
Memory: 81.23 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.15.0 - ~/.local/state/fnm_multishells/60896_1748120199386/bin/node
Yarn: 1.22.22 - ~/.local/state/fnm_multishells/60896_1748120199386/bin/yarn
npm: 10.9.2 - ~/.local/state/fnm_multishells/60896_1748120199386/bin/npm
pnpm: 8.8.0 - ~/.local/state/fnm_multishells/60896_1748120199386/bin/pnpm
Browsers:
Chrome: 136.0.7103.114
Edge: 136.0.3240.92
Safari: 18.4
npmPackages:
@auth/unstorage-adapter: ^2.0.0 => 2.9.1
next: latest => 15.3.2
next-auth: beta => 5.0.0-beta.28
react: ^18.2.0 => 18.3.1
Reproduction URL
Describe the issue
When using next-auth in a middleware the request for the lazy initialization is undefined.
How to reproduce
- pull the reproduction repository
- run the dev server
- navigate to
http://localhost:3000/middleware-example
Expected behavior
The request should be defined
Contributor 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.
Research direction
Start with the linked reproduction repository and run its development server. Navigate to http://localhost:3000/middleware-example, inspect how next-auth initializes in middleware, and verify that the request passed to lazy initialization is defined as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, node.js, react, typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100