prisma/prisma-examples

rest-nextjs-api-routes-auth CLIENT_FETCH_ERROR

qunders opened this issue · 4 comments

Hi there.

I'm following the documentation to test out the rest-nextjs-api-routes-auth example.
Logging in through Github seems to work fine, however when I write a new draft and post it, it redirects to the drafts page, but no new entry has been made. In the dev console I see the following error

[next-auth][error][CLIENT_FETCH_ERROR] 
https://next-auth.js.org/errors#client_fetch_error undefined {
  error: {},
  url: 'http://localhost:3000/api/auth/session',
  message: undefined
}

The NextAuth docs explain the error as follows

If you see CLIENT_FETCH_ERROR make sure you have configured the NEXTAUTH_URL environment variable.

In my .env file, NEXTAUTH_URL is defined as follows

NEXTAUTH_URL='http://localhost:3000'

Any help is greatly appreciated

HI. I had the same problem. Do you resolve it?

I honestly don't remember. I think i just ditched it, and went for a different approach - sorry i can't help

You can solve this problem to use getServerSession instead of getSession on 'api/post/index.ts'.
https://next-auth.js.org/getting-started/example#backend---api-route