Next.js Discord

Discord Forum

Getting Error `error=OAuthCallback` when using Google OAuth

Unanswered
Maltese posted this in #help-forum
Open in Discord
MalteseOP
Whenever i am trying locally it works for me but when deployed on signing in with same email id it's gives me above error: error=OAuthCallback

provider is written as follows:
import GoogleProvider from 'next-auth/providers/google';

export const options = {
    providers: [
        GoogleProvider({
            profile(profile) {                
                return {
                    ...profile,
                    id: profile.sub
                }
            },
            clientId: process.env.NEXT_PUBLIC_GOOGLE_OAUTH_CLEINT_ID,
            clientSecret: process.env.NEXT_PUBLIC_GOOGLE_OAUTH_SECRET
        }),        
    ],
    callbacks: {
        async session({ session, token }) {                  
            if (token) {
                session.user = {
                    name: token.name,
                    email: token.email,
                    image: token.image,
                };
                
                return session;
            }
        }
    }
}


tried following stackoverflow links, not working for me:
https://stackoverflow.com/questions/68029244/how-to-fix-api-auth-error-issue-of-next-auth-in-production

1 Reply

MalteseOP
Checked logs, getting error:
[next-auth][error][OAUTH_CALLBACK_ERROR] 
https://next-auth.js.org/errors#oauth_callback_error invalid_client (Unauthorized) {
  error: o: invalid_client (Unauthorized)
      at e.exports (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:39:35456)
      at Y.grant (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:39:15036)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Y.callback (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:39:2813)
      at async l (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:6:120505)
      at async Object.c (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:30:780)
      at async _ (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:6:102843)
      at async a (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:30:19579)
      at async e.length.t (/opt/render/project/src/frontends/.next/server/app/api/auth/[...nextauth]/route.js:30:20990)
      at async /opt/render/project/src/frontends/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36258 {
    name: 'OAuthCallbackError',
    code: undefined
  },
  providerId: 'google',
  message: 'invalid_client (Unauthorized)'
}