Google Oauthcallbackerror Signin? Error=Oauthcallback

I am adding next-auth with google provider to my next.js project in developement mode, but I am geeting this error on the browser URL : and Try signing in with a different account message on the screen. and after signing in with signIn('google') everytime the following error appears in my terminal in vscode:

[next-auth][warn][NEXTAUTH_URL]

data unauthenticated
[next-auth][error][OAUTH_CALLBACK_ERROR]
 JWT expired, now 1675094480, exp 1675094221 {
  error: RPError: JWT expired, now 1675094480, exp 1675094221
      at Client.validateJWT (D:\React_prj\ChatApp\frontend\node_modules\openid-client\lib\client.js:956:15)
      at Client.validateIdToken (D:\React_prj\ChatApp\frontend\node_modules\openid-client\lib\client.js:745:60)
      at Client.callback (D:\React_prj\ChatApp\frontend\node_modules\openid-client\lib\client.js:488:18)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async oAuthCallback (D:\React_prj\ChatApp\frontend\node_modules\next-auth\core\lib\oauth\callback.js:129:16)
      at async Object.callback (D:\React_prj\ChatApp\frontend\node_modules\next-auth\core\routes\callback.js:52:11)
      at async AuthHandler (D:\React_prj\ChatApp\frontend\node_modules\next-auth\core\index.js:201:28)
      at async NextAuthHandler (D:\React_prj\ChatApp\frontend\node_modules\next-auth\next\index.js:24:19)
      at async D:\React_prj\ChatApp\frontend\node_modules\next-auth\next\index.js:60:32
      at async Object.apiResolver (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\api-utils\node.js:372:9)      at async DevServer.runApi (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\next-server.js:488:9)
      at async Object.fn (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\next-server.js:751:37)
      at async Router.execute (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\router.js:253:36)
      at async DevServer.run (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\base-server.js:384:29)
      at async DevServer.run (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\dev\next-dev-server.js:743:20)
      at async DevServer.handleRequest (D:\React_prj\ChatApp\frontend\node_modules\next\dist\server\base-server.js:322:20) {
    name: 'OAuthCallbackError',
    code: undefined
  },
  providerId: 'google',
  message: 'JWT expired, now 1675094480, exp 1675094221'
}

everytime on the browser I see the following image (Try signing in with a different account.)even trying with another account I get this image in the browser

enter image description here

also, I use prisma as the adapter as well

the following are my codes:

[...nextauth].ts

import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import prisma from '../../../lib/prismadb';

export default NextAuth({
  adapter: PrismaAdapter(prisma),
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    }),
  ],
});

prismadb.ts

import { PrismaClient } from '@prisma/client';

declare global {
  var prisma: PrismaClient | undefined;
}

const client = globalThis.prisma || new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalThis.prisma = client;

export default client;

schema.prisma

datasource db {
  provider = "mongodb"
  url      = env("MONGODB_URI")
 
}

generator client {
  provider        = "prisma-client-js"

}

model Account {
  id  String  @id @default(auto()) @map("_id") @db.ObjectId
  userId             String
  type               String
  provider           String
  providerAccountId  String
  refresh_token      String?  @db.String
  access_token       String?  @db.String
  expires_at         Int?
  token_type         String?
  scope              String?
  id_token           String?  @db.String
  session_state      String?

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id  String  @id @default(auto()) @map("_id") @db.ObjectId
  sessionToken String   @unique
  userId       String
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
  id  String  @id @default(auto()) @map("_id") @db.ObjectId
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  accounts      Account[]
  sessions      Session[]
}

model VerificationToken {
  id  String  @id @default(auto()) @map("_id") @db.ObjectId
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

and .env.local

GOOGLE_CLIENT_ID=46255473************od0rt849b.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-*************I7SNBuJ6

MONGODB_URI =mongodb://localhost/chatapp

I tried many othersolution provided on the google and other providers but I cannot fix this issue. please help thx

I tried to login with next-auth with google as the provider and prisma as the adapter, but I get callback error

2

1 Answer

You must add These props in you env file:

GOOGLE_ID = 89249145874417-vnb9dc2uh44peu40ef7l67f3eohgdfsfsflcfm.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET = 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
MONGODB_URI =mongodb+srv://[email protected]/?retryWrites=true&w=majority
NEXTAUTH_URL =
NEXTAUTH_URL_INTERNAL =
NEXTAUTH_SECRET =o6jb9zMVmPUCm+YArIy7zfFjTIRr4566DuMZMcgjsnMXnTA=

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest