Next.js Discord

Discord Forum

NextAuth deployments problems : Session NULL

Answered
Ninhache posted this in #help-forum
Open in Discord
Avatar
Hello, got a problem using NextAuth :
I've setup everything and had 0 problems by running run dev, now, when i'm trying to deploy it i'm getting errors about URL.. (first of all it's weird because i've setup it.. but anyways)
I've figured out the session is ALWAYS null even if the signIn got sucess..

I couldnt really post a reproductible example, i can tell you i'm using a CredentialsProvider and the way i'm getting the session can be found here :
export async function getServerSideProps(context) {
  const session = await getSession(context)
  // session === NULL
  // there's a fetch here, that creates the error [CLIENT_FETCH_ERROR]
}


Anyone ever figured out a similar problem ?
And then, someone ever fix the problem ?
Answered by Ninhache
https://github.com/nextauthjs/next-auth/discussions/1466

URLs where missing, to fix i'd to add them in my .env..
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_URL_INTERNAL=http://127.0.0.1:3000
View full answer

14 Replies

Avatar
did you set up your NEXTAUTH_URL on deployment env?
Avatar
yea
but i'm deploying "locally" > yarn run build && yarn run start ..
in the .env
Avatar
bump 🤓 ..
Still the same problems :(
Avatar
I've found : https://github.com/auth0/nextjs-auth0/issues/575
and then associated SOF post : https://stackoverflow.com/questions/72457673/nextjs-next-auth-get-session-always-null

But i feel weird about this solution..
Should i put my cookie in my fetch authentification ? That's weird a bit..
And i'm keep getting null session lmao.. :^)
Avatar
https://github.com/nextauthjs/next-auth/discussions/1466

URLs where missing, to fix i'd to add them in my .env..
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_URL_INTERNAL=http://127.0.0.1:3000
Answer
Avatar
YOUHOU
SOLVED RN
Avatar
no that wont work, you right click on the solution message and choose Apps => Mark Solution
Image
Avatar
:^)
Was looking for it
thanks tho