2

我正在使用 next/auth 开发登录系统,并通过仅邀请系统实现凭据记录系统。有没有办法将重置密码链接添加到生成的/api/auth/signin页面?

4

2 回答 2

0

我看到并使用了与此类似的那个。也许这可以帮助你。

  • 从我的后端发送一个帖子来创建一个新的 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, user, context);
  });
}
  • 下次我们需要向他们发送密码重置电子邮件时,它将使用模板的“现有用户”风格

  • 邀请电子邮件密码重置链接具有可配置的 TTL - 默认为 5 天。因此,如果他们不接受邀请,它最终会超时(如果需要,我们可以向他们发送另一个)

于 2021-03-23T08:05:53.237 回答
0

您最好的选择是创建您自己的自定义登录页面 ( https://next-auth.js.org/configuration/pages ),然后您可以在其中添加您想要的“重置密码”功能

于 2021-03-22T21:24:41.933 回答