Next js - Next Auth - Keep having error=OAuthCreateAccount (



我已经设置了next-auth与GoogleProvider。

一切工作正常本地,但在生产中,我有aOAuthCreateAccount错误:api/auth/signin?错误= OAuthCreateAccount

提示"尝试使用其他帐户登录。">

我已经提供了ID &秘密的提供者,我已经放弃了我的数据库,试图用多个帐户登录…我不明白。是否存在我的生产环境无法访问的内容?

我的nextauth.js:

import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import CredentialsProvider from "next-auth/providers/credentials";
import { MongoDBAdapter } from "@next-auth/mongodb-adapter";
import clientPromise from "../../../lib/mongodb";

export default NextAuth({
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    }),
    // ...add more providers here
  ],
  secret: process.env.NEXTAUTH_SECRET,
  // Can custom page & path
  pages: {
    signOut: "/auth/signout",
    error: "/auth/error", // Error code passed in query string as ?error=
    verifyRequest: "/auth/verify-request", // (used for check email message)
    // newUser: "/auth/new-user", // New users will be directed here on first sign in (leave the property out if not of interest)
    newUser: "/recruiter/2", // New users will be directed here on first sign in (leave the property out if not of interest)
  },
  adapter: MongoDBAdapter(clientPromise),
});

和我的mongodb.js:'

import { MongoClient } from "mongodb";
const uri = process.env.MONGODB_URI;
const options = {
  useUnifiedTopology: true,
  useNewUrlParser: true,
};
let client;
let clientPromise;
if (!process.env.MONGODB_URI) {
  throw new Error("Please add your Mongo URI to .env.local");
}
if (process.env.NODE_ENV === "development") {
  // In development mode, use a global variable so that the value
  // is preserved across module reloads caused by HMR (Hot Module Replacement).
  if (!global._mongoClientPromise) {
    client = new MongoClient(uri, options);
    global._mongoClientPromise = client.connect();
  }
  clientPromise = global._mongoClientPromise;
} else {
  // In production mode, it's best to not use a global variable.
  client = new MongoClient(uri, options);
  clientPromise = client.connect();
}
// Export a module-scoped MongoClient promise. By doing this in a
// separate module, the client can be shared across functions.
export default clientPromise;

谢谢!

阅读文档。看看Stackoverflow和github线程,尝试了所有提供的解决方案,徒劳无功。

我已经设法修复它阅读这篇完整的文章:https://medium.com/geekculture/why-and-how-to-get-started-with-next-auth-61740558b45b

我在部署系统(vercel)中丢失了数据库变量:)