getServerSession returns null when the route handler is invoked from a server component fetch call #7546
Labels
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Environment
Reproduction URL
non available
Describe the issue
Using
getServerSession
inside an API route handler (as per Next.js 13+) returnsnull
when the route handler URL is invoked from within a react server component.If the route handler URL is invoked directly from the browser address bar,
getServerSession
returns the correct session objectHow to reproduce
Assume you have a simple route handler such as this and that you are logged in successfully using NextAuth.js
If you hit
http://localhost:3000/api/test
from the browser address bar, you will see printedYES SESSION
followed by a proper session object, in the terminal.If you hit
http://localhost:3000/api/test
from a server component, such as aPage.tsx
like this:You will see printed
NO SESSION
followed by{ session: null }
Expected behavior
I would expect
getServerSession
to work the same when it's called inside an App router route-handler function, regardless if the route-handler is invoked from within a server component or notThe text was updated successfully, but these errors were encountered: