Home  >  Q&A  >  body text

Next Auth on Vercel encountered a server error

I am using Google as the authentication provider for next authentication. Configure all environment variables in production and development. It runs perfectly in development mode on my local machine but in production it shows the error "Server Error There is a problem with the server configuration.

Whenever I try to log in, check the server logs for more information.

I deployed the website to vercel and set the google id, secret and NEXTAUTH_URL variables there.

This is the code I use

import NextAuth from "next-auth"
import GoogleProvider from 'next-auth/providers/google'
export const authOptions = { // Configure one or more authentication providers
  providers: [
    GoogleProvider({ 
      clientId: process.env.GOOGLE_ID, 
      clientSecret: process.env.GOOGLE_SECRET, }), // ...add more providers here
  ],
}

export default NextAuth(authOptions)

I tried adding all environment variables to vercel but it didn't work and I also redeployed several times

P粉420868294P粉420868294184 days ago414

reply all(1)I'll reply

  • P粉442576165

    P粉4425761652024-03-22 12:37:41

    Maybe it has something to do with nextauth itself. Both secrets should be set on vercel:

    jwt: {
        secret: process.env.JWT_SECRET,
      },
    secret: process.env.SECRET,

    reply
    0
  • Cancelreply