Next.js Discord

Discord Forum

NextAuth Providers work in dev but not in production

Answered
Sloth bear posted this in #help-forum
Open in Discord
Avatar
Sloth bearOP
I am using Google and Azure AD providers. I believe I set the providers up properly with their respective env variables and redirect URIs. When I go to login, I get sent to my custom sign in page. When I select either provider, it immediately redirects me to /api/auth/error. I am deploying the app through Vercel. I have no NEXTAUTH_URL env variable (as recommended in the docs) but I do have a SECRET env variable set. Here are my auth options:
...
adapter: PrismaAdapter(db),
    session: {
        strategy: 'jwt',
    },
    secret: process.env.SECRET,
    pages: {
        signIn: '/signin',
    },
    providers: [
        GoogleProvider({
            clientId: getGoogleCredentials().clientId,
            clientSecret: getGoogleCredentials().clientSecret,
        }),
        AzureADProvider({
            clientId: getAzureCredentials().clientId,
            clientSecret: getAzureCredentials().clientSecret,
            tenantId: getAzureCredentials().tenantId,
        }),
    ],
...

I have no idea what the issue is and I don't even know where to start to determine what the issue is because there is no error details. Any help would be greatly appreciated.
Answered by Sloth bear
Resolved. For those having a similar issue, I had a vercel.json config file. Why did I have it? I'm not sure. The contents were as follows:
{
    "rewrites": [
        {
            "source": "/(.*)",
            "destination": "/"
        }
    ]
}

I deleted this file and authentication now works.
View full answer

2 Replies

Avatar
Sloth bearOP
This shows up in the runtime logs when I click on a provider to sign in with.
Image
Avatar
Sloth bearOP
Resolved. For those having a similar issue, I had a vercel.json config file. Why did I have it? I'm not sure. The contents were as follows:
{
    "rewrites": [
        {
            "source": "/(.*)",
            "destination": "/"
        }
    ]
}

I deleted this file and authentication now works.
Answer