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.
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,
})
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With