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

问题描述

如何在启动应用程序时将电子邮件中的代码中继(获取自动提交)到我们的应用程序中?我使用的是 react native aws-amplify forgotPasswordSubmit 函数

Auth.forgotPasswordSubmit(username,code,new_password)

解决方法

文档说明:

    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));

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

具体来说,您可以使模板将您发送到带有 :slug 的网站页面,用于传递到“配置代码区域”的 URL,然后 useEffect 可以在此之后重新加载页面,以提交信息。

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

,

您可以参考此文档了解更多信息:

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

,

我猜你已经用

开始了密码恢复过程
Auth.forgotPassword(username)

因此,您已经知道用户名,并且用户可能已经收到一封带有验证码的电子邮件。

您不能只是将电子邮件中的数据“提取”到您的应用中。您唯一能做的就是在电子邮件中创建一个链接,单击该链接会打开您的应用程序。例如,此链接看起来像 https://yourapp.com/recovery?code=12345656 这称为 "Deep Linking"

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

Auth.forgotPasswordSubmit(username,new_password)

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