-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to setUser on Next.js middleware + next-auth #8508
Comments
I'm also getting this error on the terminal
None of these suggestions worked for me. |
Don't know if it's related for certain, but I'm seeing the same issue with
Could be a separate issue or could be an ingestion issue if it's happening across SDKs. |
Could you pass in maybe you're trying to call Otherwise a reproduction of some kind would help us a lot! |
@naofalleoagusta The reason you don't have a user show up on your event is that middleware (and any other edge runtime features) basically runs in its own process. Any context you give to Sentry in middleware is only available for things happening inside the middleware. The event you shared was inside a server component - which is in a different context than the middleware. If you want the user recorded for errors there, you also need to set the user in that context. I wouldn't say this is by design but rather how Next.js works. Closing this because it's not something we can (easily) change from the SDK's side and we're not planning on implementing user propagation across Next.js runtimes at the moment. |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
7.57.0
Framework Version
Next.js 13.2.4
Link to Sentry event
https://govtech-procurement.sentry.io/issues/4307368258/?query=is%3Aunresolved&referrer=issue-stream&stream_index=1
SDK Setup
Mostly just from the docs, with the addition of an environment options.
Steps to Reproduce
Attempting to use setUser on Next.js middleware+withAuth HOC from next-auth.
The middleware setup looking like this :
And yes I have made sure, I have logged in because the middleware only get executed when you are logged in.
Also, I have tried calling the
setUser
on my client provider usinguseEffect
:That didn't work too
Expected Result
The error log should've set the
user.id
Actual Result
Sentry doesn't log the
user.id
The text was updated successfully, but these errors were encountered: