0

hey i have a bug when i sign up with credentials in mongo i got the user schema after that if i log in with google provider with the same email i just have bag that returned me to the sign in page someone know how can i access the existing user and sync between them or just return the user?

export default NextAuth({
providers: [
GoogleProvider({
  clientId: process.env.GOOGLE_CLIENT_ID,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),

// apply facebook login//
FacebookProvider({
  clientId: process.env.FACEBOOK_CLIENT_ID,
  clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
}),
CredentialsProvider({
  id: "credentials",
  name: "Credentials",
  credentials: {
    email: {
      label: "Email",
      type: "text",
    },
    password: {
      label: "Password",
      type: "password",
    },
  },
  async authorize(credentials) {
    await dbConnect();

    // Find user with the email
    const user = await User.findOne({
      email: credentials?.email,
    });

    // Email Not found
    if (!user) {
      throw new Error("Email is not registered");
    }

    // Check hased password with DB hashed password

    const isPasswordCorrect = await compare(
      credentials.password,
      user.hashedPassword
    );

    // Incorrect password
    if (!isPasswordCorrect) {
      throw new Error("Password is incorrect");
    }

    return user;
    },
    }),
     ],
    pages: {
    signIn: "/auth/signin",
    },
    secret: process.env.AUTH_SECRET,
    debug: process.env.NODE_ENV === "development",
    adapter: MongoDBAdapter(clientPromise),
     session: { strategy: "jwt" },
    jwt: {
    secret: process.env.AUTH_JWT_SECRET,
    },
  });

0 Answers0