google next-auth error: invalid_client even if client id is correct

my auth was working fine but now I keep getting this error [next-auth][error][OAUTH_CALLBACK_ERROR] https://next-auth.js.org/errors#oauth_callback_error invalid_client (Unauthorized) { error: OPError: invalid_client (Unauthorized) at processResponse (/home/blue/Projects/tracker/node_modules/openid-server.js:157:99 { name: 'OAuthCallbackError', code: undefined }, providerId: 'google', message: 'invalid_client (Unauthorized)' } (deleted some of the error)
Errors | NextAuth.js
This is a list of errors output from NextAuth.js.
7 Replies
Ani
Ani15mo ago
I have tried reseting my credentials my auth.ts file
Ani
Ani15mo ago
import type { GetServerSidePropsContext } from "next"; import { getServerSession, type NextAuthOptions, type DefaultSession, } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import { env } from "../env/server.mjs"; import { prisma } from "./db"; import type { Role } from "@prisma/client"; import { takeCoverage } from "v8"; export interface ClubToRole { [key: string]: Role; } / * Module augmentation for next-auth types. * Allows us to add custom properties to the session object and keep type * safety. * * @see https://next-auth.js.org/getting-started/typescript#module-augmentation / declare module "next-auth" { interface Session extends DefaultSession { user: { id: string; // roles assign type to ClubToRole roles: ClubToRole; } & DefaultSession["user"]; } // interface User { // // ...other properties // // role: UserRole; // } }
TypeScript | NextAuth.js
NextAuth.js has its own type definitions to use in your TypeScript projects safely. Even if you don't use TypeScript, IDEs like VSCode will pick this up to provide you with a better developer experience. While you are typing, you will get suggestions about what certain objects/functions look like, and sometimes links to documentation, examples, ...
Ani
Ani15mo ago
/ * Options for NextAuth.js used to configure adapters, providers, callbacks, etc. * * @see https://next-auth.js.org/configuration/options */ export const authOptions: NextAuthOptions = { callbacks: { async session({ session, user }) { if (session.user) { session.user.id = user.id; const roles: ClubToRole = {}; // session.user.role = user.role; <-- put other properties on the session here const trackers = await prisma.tracker.findMany({ where: { userId: user.id, }, include: { club: true } }) trackers.forEach((tracker) => { roles[tracker.club.id] = tracker.role; }) session.user.roles = roles; } return session; }, }, providers: [ GoogleProvider({ clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_ID, }), / * ...add more providers here. * * Most other providers require a bit more work than the Discord provider. For example, the * GitHub provider requires you to add the refresh_token_expires_in field to the Account * model. Refer to the NextAuth.js docs for the provider you want to use. Example: * * @see https://next-auth.js.org/providers/github */ ], }; /** * Wrapper for getServerSession so that you don't need to import the authOptions in every file. * * @see https://next-auth.js.org/configuration/nextjs */ export const getServerAuthSession = (ctx: { req: GetServerSidePropsContext["req"]; res: GetServerSidePropsContext["res"]; }) => { return getServerSession(ctx.req, ctx.res, authOptions); };
Options | NextAuth.js
Environment Variables
GitHub | NextAuth.js
GitHub returns a field on Account called refreshtokenexpires_in which is a number. See their docs. Remember to add this field to your database schema, in case if you are using an Adapter.
Next.js | NextAuth.js
unstable_getServerSession
Ani
Ani15mo ago
I've been awake for a while so sorry if I missed anything my auth was working and now just isn't update I have now tried with multiple accounts credentials it still throws the same error
lyricaldevil
lyricaldevil5mo ago
Did you ever figure out what the issue was here? I have the same issue - google auth suddenly stopped working despite seemingly nothing changing.
Wiznet
Wiznet5mo ago
Also experiencing this issue
tobsai
tobsai5mo ago
I have also seen this issue. I have an older t3 app I setup a year ago that doesn't have this issue. I have the same setup as the old one. I can see the bearer token coming back correctly from the Google response in the network trace and the cookie looks correct. I'm not sure where else to look.
Want results from more Discord servers?
Add your server
More Posts