nextauthjs / nextauthjs/next-auth

Lazy Initialization does not work in middleware

Open
#13,003 1 comment 4 reactions 0 assignees View on GitHub

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

https://github.com/paul-vd/reproduction-next-auth-lazy-initialization/commit/6b03b4e82dd3a5fb342e80efc8cbd14b0f657218

Describe the issue

When using next-auth in a middleware the request for the lazy initialization is undefined.

How to reproduce
  1. pull the reproduction repository
  2. run the dev server
  3. navigate to http://localhost:3000/middleware-example
Expected behavior

The request should be defined

Contributor guide

Open the contributing guide

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.