Auth0 with next-auth running locally, but not on Vercel


I am developing an admin area for a website, using NextJS 10, Tailwind and next-auth for the auth layer. As next-auth provider I use Auth0, which works like a charm locally, unfortunately, not on the server (Vercel).

Instead of being redirected to auth0, I get an error:
Errors | NextAuth.js /api/auth/csrf TypeError: Failed to fetch

As the link in the error msg suggests, NEXTAUTH_URL envionment variable should be added, which, it is, pointing to the canonical URL of the site. I also checked the Allowed Redirect URLs for the app in the dashboard, this all seems fine.

Vercel’s serverless function logs show hits onto /admin and /api/auth/session as expected, but then nothing else happens, no redirect… I have only the clue with csrf token mismatch thing, but I don’t know enough about it to debug properly.

I am running out of ideas, perhaps someone here has one :slightly_smiling_face:

1 Like

I had a similar problem. I resolved it by removing another api folder that was on the same directory level as the pages directory. I hope that helps!

1 Like

Thanks for sharing that with the rest of community!