Next.js Discord

Discord Forum

getServerSession returns undefined ONLY when deployed

Unanswered
Red-tailed Hawk posted this in #help-forum
Open in Discord
Red-tailed HawkOP
Hey! I'm developing a webapp using next.js 13 app router with next auth and mongodb. My getServerSession works in local development but when I deploy it on vercel, it apparently returns undefined. The api endpoints apparently work even in production in the route.js files which also use getServerSession to access the session of the user. In addition, useSession also works both in development and production.

I'm stuck on this and I really need help. Please give your suggestions.

I at least expected getServerSession to be unable to work in both development and production. But the problem occurs only in production.

For a more detailed description, checkout my post on stackoverflow: https://stackoverflow.com/questions/77133849/getserversession-is-null-or-undefined-only-when-deployed

1 Reply

Did you set next auth environment variables correctly