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

Hello,

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:
[next-auth][error][client_fetch_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:
Thanks

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!

Hey team!

This topic seems related to the new Auth0 Integration available new in Vercel Marketplace. This is the first version of this integration, and we welcome your feedback to improve future iterations.

You’ll need an existing Vercel project to use the new integration to build and customize the Identity flow. You can either import your project into Vercel or use a Vercel template so you don’t have to start from scratch like our SaaStart template to deploy a production-ready B2B SaaS app in minutes (learn more here).

If you find yourself having questions regarding this new integration for the next two weeks, we are hosting an Ask Me Anything session. Our Product Expert will provide comprehensive written answers on August 8th from 8 AM to 10 AM PST.

Find out more about Auth0 Integration and learn more about AMA.

Thanks!
Dawid