如何解决NextAuth.js - 凭证认证,添加重置密码按钮
我正在使用 next/auth 开发登录系统,并且使用仅邀请系统实现了凭据日志记录系统。有没有办法将重置密码链接添加到生成的 /api/auth/signin
页面?
解决方法
最好的办法是创建您自己的自定义登录页面 (https://next-auth.js.org/configuration/pages),然后您可以在其中添加您想要的“重置密码”功能
,我看到并使用了与此类似的一个。也许这可以帮助您。
- 从我的后端发送帖子以创建一个新的 auth0 用户。此时 auth0 user.email_verified = false。
- 发送帖子以触发新用户的密码重置电子邮件。
{% if user.email_verified == false %}
<h1>Invitation to our awesome app</h1>
<p>Please verify your email address and set your initial password by clicking the following link:</p>
<p><a href="{{ url }}">Confirm my account</a></p>
{% else %}
<h1>Password Change Request</h1>
<p>You have submitted a password change request. </p>
<p>If it wasn't you please disregard this email and make sure you can still login to your account. If it was you,then to <strong>confirm the password change <a href="{{ url }}">click here</a></strong>.</p>
{% endif %}
<p>If you have any issues with your account,please don’t hesitate to contact us at 1-888-AWESOMECO.</p>
<br>
Thanks!
<br>
- 在密码重置电子邮件模板上配置重定向,以便当用户单击邀请链接时,系统会提示他们重置密码,然后他们将被重定向到我们的应用,然后要求他们登录
- 我添加了一个 auth0 规则来在第一次登录/密码重置时设置 email_verified = true(这是一个预设选项)
}
if (user.email_verified || !user.last_password_reset) {
return callback(null,user,context);
}
// Set email verified if a user has already updated his/her password
request.patch({
url: userApiUrl + user.user_id,headers: {
Authorization: 'Bearer ' + auth0.accessToken
},json: { email_verified: true },timeout: 5000
},function(err,response,body) {
// Setting email verified isn't propagated to id_token in this
// authentication cycle so explicitly set it to true given no errors.
context.idToken.email_verified = (!err && response.statusCode === 200);
// Return with success at this point.
return callback(null,context);
});
}
-
下次我们需要向他们发送密码重置电子邮件时,它将使用模板的“现有用户”风格
-
邀请电子邮件密码重置链接有一个可配置的 TTL – 默认为 5 天。所以如果他们不接受邀请,它最终会超时(如果需要,我们可以再给他们发送一个)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。