我正在使用NextAuth.js进行Next.js身份验证。登录功能正常,但是在错误的凭据上,页面仍在重新加载。它不显示任何错误。我需要处理错误以显示某种提示消息。
signIn("credentials", {
...values,
redirect: false,
})
.then(async () => {
await router.push("/dashboard");
})
.catch((e) => {
toast("Credentials do not match!", { type: "error" });
});
NextAuth v4.10.3
在登录成功后没有注入 session,因此router.push('/dashboard')
将携带session=null
。为了解决这个问题,请执行window.location.replace('/dashboard')
,将会触发完整的刷新。希望这个问题很快就能得到解决。更多细节请参考 https://github.com/nextauthjs/next-auth/issues/1264。 - Gabriel Linassiv4.21.1
版本中仍然存在。使用router.push
后跟router.reload
并不能解决这个问题,但是使用window.location.replace
可以解决。 - Henry Fungv4.24.3
版本中修复。 - undefined