繁体   English   中英

如何通过链接处理忘记密码/重置密码

[英]How to handle forgot password/ reset password through link

如何在启动时将 email 中的代码中继(获取和自动提交)到我们的应用程序中? 我使用反应原生 aws-amplify 默认forgotPasswordSubmit function。

Auth.forgotPasswordSubmit(username, code, new_password)

文档 state 这个:

    import { Auth } from 'aws-amplify';

// Send confirmation code to user's email (this sends the email, and consolelogs what is sent)
Auth.forgotPassword(username)
    .then(data => console.log(data))
    .catch(err => console.log(err));

// Collect confirmation code and new password, then (this lets you reset the password)
Auth.forgotPasswordSubmit(username, code, new_password)
    .then(data => console.log(data))
    .catch(err => console.log(err));

要让它自动从 email 转到链接,您需要使用“电子邮件模板”做一些事情

具体来说,您可以使模板将您发送到一个网站页面,其中包含一个:slug 用于传递到“conformation code area”的 URL 并且 useEffect 可以在此之后重新加载页面,以提交信息。

虽然我之前没有使用过任何 AWS。

您可以参考此文档以获取更多信息:

https://docs.amplify.aws/lib/auth/manageusers/q/platform/js#forgot-password

我猜,您已经开始了密码恢复过程

Auth.forgotPassword(username)

因此,您已经知道用户名,并且用户可能收到了带有验证码的 email。

您不能只从 email 将数据“获取”到您的应用程序中。 您唯一能做的就是在 email 中创建一个链接,单击该链接会打开您的应用程序。 例如,此链接将类似于https://yourapp.com/recovery?code=12345656这称为“深度链接”

这将允许您从点击的链接中提取验证码。 现在,您将不得不要求用户输入新密码。 一旦您获得所有必要的信息(即预先输入的用户名、验证码和新密码),您终于可以拨打电话了

Auth.forgotPasswordSubmit(username, code, new_password)

我不会在这里提供任何代码,因为我认为复制文档或一些教程没有多大意义。 查看文档或那里的众多教程之一。 如果您的代码有特定问题,请随时使用详细信息更新您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM