nextauthjs / nextauthjs/next-auth
next-auth v4 session.update() not working right after signin
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
next-auth@^4.24.11:
version "4.24.11"
resolved "https://registry.npmjs.org/next-auth/-/next-auth-4.24.11.tgz#16eeb76d37fbc8fe887561b454f8167f490c381f"
System:
OS: macOS 14.0
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 9.30 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
Browsers:
Safari: 17.0
Reproduction URL
https://github.com/hehehai/next-auth-otp
Describe the issue
Because neither session and loading changed after login.
session.update will bail out on the first conditional because session is null.
How to reproduce
Add
session.update(); // also add const session = useSession();
The update function is not going through. And session not updated.
Expected behavior
The session should be updated.
It seems fixed in v5. So I guess it should also be fixed in v4?
https://github.com/nextauthjs/next-auth/blob/39dd3b92de194c1a835f2d87631f4deb9d9fdf65/packages/next-auth/src/react.tsx#L514
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 packages/next-auth/src/react/index.tsx around line 472 and reproduce the behavior using src/app/login/page.tsx at lines 33-35 from the linked example. Compare the v4 behavior with the referenced v5 implementation, then verify that session.update() runs after sign-in and that the session is updated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, react, typescript
- Domain
- authentication, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100