如何处理Next中的OAuthAccountNotLinked错误,使用NextAuth、Prisma和MongoDB的js应用程序?

pftdvrlh  于 2023-04-30  发布在  Go
关注(0)|答案(1)|浏览(79)

我有下一个。js应用程序,使用NextAuth进行身份验证,使用Prisma和MongoDB进行数据库管理。该应用程序支持通过Github和凭据进行身份验证。但是,如果用户使用其电子邮件创建帐户,则无法使用第三方应用程序登录并收到OAuthAccountNotLinked错误。
处理此错误的最佳方法是什么?具体来说,如何向用户显示自定义文本消息或发送吐司通知,以告知他们问题并提供如何解决问题的说明?
edit/我试图创建一个异步函数,然后等待响应,但我似乎不工作。我不知道我该怎么做。.

const handleGithubLogin = async () => {
    await signIn("github", { redirect: false })
    .then(async (res) => {
        console.log(res)
        console.log("Here")
    })
    .catch((err) => {
        console.log(err)
        console.log("Error here")
    })
    
}

我也试过其他方法。

nhaq1z21

nhaq1z211#

我发现的一个解决方案是这样的:

const { error } = useRouter().query

if(error) {
   toast("Error")
}

然而,问题是,而不是只有一个吐司,我得到了4个(或2个),我不知道为什么。

相关问题