【问题标题】:How to handle forgot password/ reset password through link如何通过链接处理忘记密码/重置密码
【发布时间】:2021-07-30 13:00:19
【问题描述】:

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

Auth.forgotPasswordSubmit(username, code, new_password)

【问题讨论】:

    标签: javascript react-native aws-amplify forgot-password reset-password


    【解决方案1】:

    文档说明了这一点:

        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 的网站页面,该页面用于传递到“conformation code area”的 URL,并且 useEffect 可以在此之后重新加载页面,以提交信息。

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

    【讨论】:

    • 感谢您的回答。我已经尝试了 android.manifest 文件中的深层链接。猜猜链接正在工作,但它没有导航到我想要的屏幕。错误:无效的挂钩调用。钩子只能在函数组件的主体内部调用。这可能是由于以下原因之一: 1. 你可能有不匹配的 React 版本和渲染器(例如 React DOM) 2. 你可能违反了 Hooks 规则 3. 你可能有多个 React 副本它给了我这个错误的同一个应用程序。还有我如何获得链接末尾的代码
    • 如果你的函数组件没有用大写字母拼写,也会发生这种情况。
    • 该错误几乎总是意味着您要么“违反了钩子规则”,要么出于某种原因,您没有使用大写字母作为函数组件的名称。
    • 您需要发布整个代码。很可能您将钩子放在错误的部分。 youtube 上的 codevolution 在 hooks 上有非常具体和简单的视频
    • 您好,感谢您的回答。这是我的代码const resetLinking = { prefixes: ['password://forgot'], config: { screens: { ResetPassword:{ path: 'ResetPassword', // parse: { // code: (code) => ${code}` // } } } } }`。我会检查 codevolution 肯定谢谢。
    【解决方案2】:

    【讨论】:

      【解决方案3】:

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

      Auth.forgotPassword(username)
      

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

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

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

      Auth.forgotPasswordSubmit(username, code, new_password)
      

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

      【讨论】:

      • 感谢您的回答。我已经尝试了 android.manifest 文件中的深层链接。猜猜链接正在工作,但它没有导航到我想要的屏幕。 Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app 它给了我这个错误。还有我如何获得链接末尾的代码
      猜你喜欢
      • 2015-12-09
      • 1970-01-01
      • 2020-08-26
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 2022-12-18
      • 2018-11-05
      • 2012-09-21
      相关资源
      最近更新 更多