Next-Auth getSession is returning null in my development environment
Asked Answered
E

3

7

I'm using the following code in one of my pages:

export async function getServerSideProps(context) {
  const session = await getSession(context)
  return {
    props: { session }
  }
}

and the session is returning null. I get the following error:

[next-auth][error][client_fetch_error] [
  'http://localhost:3000/api/auth/session',
  FetchError: request to http://localhost:3000/api/auth/session failed, reason: read ECONNRESET

if I try to navigate to http://localhost:3000/api/auth/session in my browser I get the session object normally. Also, my co-worker has the same code in his machine and it is working fine for him.

The only difference that I know between my environment and his is that I'm using windows and he is using mac. Not really sure if this can be causing the problem here.

Ensoll answered 26/1, 2021 at 21:47 Comment(2)
Did you get any solution for this?Associationism
I had this same problem and it was because I put the next-auth environment variables in the wrong place.Lest
T
1

Try to delete .next folder in your root directory and try again

Tiana answered 29/10, 2021 at 9:20 Comment(0)
B
1

This problem is happening due to not specifying e.preventDefault() on login button.

The working code should look like this :-

async function login(e) {
    e.preventDefault(); //Add this to your code.

    const getLoginStatus = await signIn("credentials", {
        redirect: false,
        username,
        password,
    })
};
Burgee answered 12/4, 2022 at 18:0 Comment(0)
W
0

I had the same issue and solved it by using straight ip address/domain name.

Try to use 127.0.0.1 instead of localhost, e.g.: NEXTAUTH_URL=http://127.0.0.1:3000

Walloon answered 8/3, 2022 at 19:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.