Search code examples
next.jsoauthvercelnext-auth

Vercel Google OAuth JSON error when trying to sign in but it works in localhost, what can be the problem with vercel?


I reviewed everything, my client ID/Secret and everything is fine in my environment variables, when I click to sign in with google in localhost it works perfectly but in vercel it throws this error

[GET] /api/auth/error?error=OAuthSignin

Here is my [...nextauth].js code

import NextAuth from "next-auth/next";
import GoogleProvider from "next-auth/providers/google";
import FacebookProvider from "next-auth/providers/facebook";
import { MongoDBAdapter } from "@next-auth/mongodb-adapter";
import clientPromise from "../../../lib/mongodb";

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      authorization: {
        
        params: {
          
          redirect_uri: "https://theracakecairo.com/api/auth/callback/google",
          prompt: "consent",
          scope: "email",
          
        },
      },
    }),
    FacebookProvider({
      clientId: process.env.FACEBOOK_CLIENT_ID,
      clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
      authorization: {
        params: {
          redirect_uri: "https://theracakecairo.com/api/auth/callback/facebook",
          prompt: "consent",
          // access_type: "offline",
          scope: "email",
          response_type: "code",
        },
      },
    }),
  ],
  debug: true,
  secret: process.env.NEXTAUTH_SECRET,
  adapter: MongoDBAdapter(clientPromise),
  callbacks: {
    async session({ session, token, user }) {
      session.user._id = user.id;
      return session;
    },
  },
  // session: {
  //   strategy: "database",
  //   maxAge: 30 * 24 * 60 * 60
  // }
});

https://next-auth.js.org/errors Walked through the 3 possible error causes and still nothing works


Solution

  • Update:

    This issue has been corrected by the Vercel team. Please redeploy your application.

    https://github.com/nextauthjs/next-auth/issues/6688#issuecomment-1426614069


    The issue is being discussed on GitHub:

    https://github.com/nextauthjs/next-auth/issues/6688

    https://github.com/nextauthjs/next-auth/issues/6685

    Some users say that migrating to Netlify has solved their issues.

    https://github.com/nextauthjs/next-auth/issues/6685#issuecomment-1426535665