【发布时间】:2021-05-26 04:08:15
【问题描述】:
我正在使用 next/auth 开发登录系统,并使用仅限邀请的系统实现凭据记录系统。有没有办法将重置密码链接添加到生成的/api/auth/signin 页面?
【问题讨论】:
我正在使用 next/auth 开发登录系统,并使用仅限邀请的系统实现凭据记录系统。有没有办法将重置密码链接添加到生成的/api/auth/signin 页面?
【问题讨论】:
您最好创建自己的自定义登录页面 (https://next-auth.js.org/configuration/pages),然后您可以在其中添加您想要的“重置密码”功能
【讨论】:
我看到并使用了与此类似的那个。也许这可以帮助你。
{% 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>
}
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, user, context);
});
}
下次我们需要向他们发送密码重置电子邮件时,它将使用模板的“现有用户”风格
邀请电子邮件密码重置链接具有可配置的 TTL - 默认为 5 天。因此,如果他们不接受邀请,它最终会超时(如果需要,我们可以向他们发送另一个)
【讨论】: