Skip to content

CLIENT_FETCH_ERROR when requesting to /api/auth/session, reason: read ECONNRESET #3330

Answered by smeijer
italodeandra asked this question in Help
Discussion options

You must be logged in to vote

Is getSession problematic when using on getServerSideProps?

It might. getSession is meant to run on the client. As it uses fetch to request the user object from the session API route (/api/auth/session) managed by next-auth, a single page request can result in multiple network requests if getServerSideProps uses getSession to obtain the user information. Every time you'll invoke getSession, the server will execute another network request against itself.

My way to bypass this problem, was to create a getSessionFromCookie helper. A small function that reads the JWT token from the cookie header, and decodes that instead.

I'm not saying my solution is the best or fault-free. It supports our…

Replies: 10 comments 25 replies

Comment options

You must be logged in to vote
18 replies
@smeijer
Comment options

@JavierMartinz
Comment options

@italodeandra
Comment options

@JavierMartinz
Comment options

@smeijer
Comment options

Comment options

You must be logged in to vote
1 reply
@oogunjob
Comment options

Answer selected by italodeandra
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@jvillalbaj2lc
Comment options

@cvega
Comment options

@sarzeez
Comment options

@benitazhang
Comment options

Comment options

You must be logged in to vote
1 reply
@aamon40
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@kr-mustali
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet