-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Open
Labels
bugSomething isn't workingSomething isn't workingtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Description
Environment
System:
OS: Windows 11 10.0.26100
CPU: (12) x64 AMD Ryzen 5 4600G with Radeon Graphics
Memory: 3.47 GB / 15.37 GB
Binaries:
Node: 22.17.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.15.0 - ~\AppData\Local\pnpm\pnpm.EXE
Browsers:
Edge: Chromium (139.0.3405.125)
Internet Explorer: 11.0.26100.1882
npmPackages:
@auth/prisma-adapter: ^1.0.14 => 1.6.0
next: 15.5.0 => 15.5.0
next-auth: 5.0.0-beta.29 => 5.0.0-beta.29
react: 19.1.1 => 19.1.1
Reproduction URL
https://github.com/0-Sandy/recursos-sanignacio
Describe the issue
In my project, I need users who sign in with OAuth to set a role after signing in. I have middleware that checks req.auth.user.role
and redirects users to a "complete profile" page until they choose a role.
However, calling update()
from useSession()
does not update req.auth
on the middleware, so the middleware continues to redirect the user even after the role is set.
Is there a recommended way to refresh or update req.auth
in middleware, so he sees the new role immediately?
How to reproduce
-
Setup project
- Clone the repository and install dependencies:
npm install
- Set up the database with Prisma:
npx prisma db push npx prisma generate
- Configure environment variables for Google OAuth and NextAuth.
- Clone the repository and install dependencies:
-
Start the development server
npm run dev
-
Sign in with OAuth (Google)
- Log in with a Google account that does not have a
role
yet. - The middleware should redirect to
/complete-profile
becausereq.auth.user.role === null
.
- Log in with a Google account that does not have a
-
Complete the profile form
- Select a role (STUDENT, TEACHER or ADMIN) and submit.
- The API successfully updates the user’s
role
in the database.
-
Observe the bug
- The middleware continues to redirect the user to
/complete-profile
. req.auth.user.role
is stillnull
in the middleware, even though the database is updated.- Calling
useSession().update()
on the client does not refreshreq.auth
.
- The middleware continues to redirect the user to
Expected behavior
- After updating the role, the middleware should detect the new role and stop redirecting.
Actual behavior
- The middleware continues to redirect because
req.auth.user.role
does not reflect the updated role immediately.
CoffeSiberian
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.