Next.js Discord

Discord Forum

NexrAuth: OAuthCallbackError: failed to validate JWT signature

Unanswered
Pulx/Mars posted this in #help-forum
Open in Discord
[next-auth][error][OAUTH_CALLBACK_ERROR] 
https://next-auth.js.org/errors#oauth_callback_error failed to validate JWT signature {
  error: 985 | export default "";
                     ^
OAuthCallbackError: failed to validate JWT signature
 code: "undefined"

      at asyncFunctionResume (native:1:1)
      at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native:1:1)
      at promiseReactionJob (native:1:1)
      at processTicksAndRejections (native:1:1)
,
  providerId: "google",
  message: "failed to validate JWT signature",
}

code:
import clientPromise from "@/libs/mongodb";
import Google from "next-auth/providers/google";
import type { NextAuthOptions } from "next-auth";
import { MongoDBAdapter } from "@auth/mongodb-adapter";
import { Adapter } from "next-auth/adapters";
export const authOptions: NextAuthOptions = {
  providers: [
    Google({
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
      profile(profile) {
        return {
          id: profile.sub,
          name: profile.name,
          email: profile.email,
          image: profile.picture,
        };
      },
    }),
  ],
  secret: process.env.NEXTAUTH_SECRET as string,
  session: {
    strategy: "jwt",
    maxAge: 30 * 24 * 60 * 60,
  },
  jwt: {
    secret: process.env.NEXTAUTH_SECRET as string,
  },
  debug: process.env.NODE_ENV === "development",
  useSecureCookies: false, // Set to true if using HTTPS
  callbacks: {
    async signIn() {
      return true;
    },
    async session({ session, token }) {
      session.user = token.user as any;
      return session;
    },
    async jwt({ token, user }) {
      if (user) {
        token.user = user;
      }
      return token;
    },
  },
  adapter: MongoDBAdapter(clientPromise) as Adapter,
};

all .env are valid

2 Replies

Can't figure out why isn't working.
FIXED: WSL2 doesn't support this for some reasons.
OS: WINDOWS 10 PRO,
WSL2: UBUNTU 22.04