I'm using NextAuth for authentication and URQL's authExchange. The idea is to attach an accessToken in the Authorization
header.
// ...
import { authExchange } from '@urql/exchange-auth'
import { getSession } from 'next-auth/react'
getAuth: async ({ authState }) => {
// for initial launch, fetch the auth state from storage (local storage, async storage etc)
if (!authState) {
const session = await getSession()
if (session && session.user.accessToken) {
return { token: session.user.accessToken }
}
return null
}
return null
},
When I start the server, it prints [next-auth][error][CLIENT_FETCH_ERROR] https://next-auth.js.org/errors#client_fetch_error request to http://localhost:4200/api/auth/session failed, reason: connect ECONNREFUSED 127.0.0.1:4200
The error is caused by getSession()
, but why does that happen and is there any potential fix?