我使用NextAuth.js进行Next.js身份验证。登录很好,但是页面仍然在错误的凭据上重新加载。它没有显示出任何错误。我需要处理错误来显示某种祝酒词。
signIn("credentials", {
...values,
redirect: false,
})
.then(async () => {
await router.push("/dashboard");
})
.catch((e) => {
toast("Credentials do not match!", { type: "error" });
});
发布于 2022-01-18 18:52:04
当将redirect: false
传递给其选项时,signIn
将返回一个始终解析为具有以下格式的对象的Promise
。
{
error: string | undefined // Error code based on the type of error
status: number // HTTP status code
ok: boolean // `true` if the signin was successful
url: string | null // `null` if there was an error, otherwise URL to redirected to
}
您必须处理then
块中的任何错误,因为它不会抛出错误。
signIn("credentials", { ...values, redirect: false })
.then(({ ok, error }) => {
if (ok) {
router.push("/dashboard");
} else {
console.log(error)
toast("Credentials do not match!", { type: "error" });
}
})
https://stackoverflow.com/questions/70165993
复制相似问题