简体   繁体   中英

How to handle forgot password/ reset password through link

How to relay(fetch and auto submit) the code from email into our app upon launching it? Im using react native aws-amplify default forgotPasswordSubmit function.

Auth.forgotPasswordSubmit(username, code, new_password)

docs state this:

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

To have it so that it automatically goes from the email to the link would require you to do something with the "email template"

specifically, you can make it so that the template send you to a website page with a:slug for the URL that is passed into the "conformation code area" and useEffect could reload the page after this, to submit the information.

though I have not used anything AWS before.

You can refer to this doc for more information:

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

I guess, you already started the password recovery process with

Auth.forgotPassword(username)

so, you already know the username, and the user probably has received an email with a verification code.

You can't just "fetch" data from an email into your app. The only thing you can do is, creating a link in the email, which, when clicked opens your app. This link will for instance look like https://yourapp.com/recovery?code=12345656 This is called "Deep Linking"

This will allow you to extract the verification code from the clicked link. Now, you will have to ask the user for a new password. Once you have all necessary information (ie the preentered username, the verification code and the new password) available, you can finally call

Auth.forgotPasswordSubmit(username, code, new_password)

I won't provide any code here, as I don't see much sense in copying the docs or some tutorial. Have a look at the docs or one of the many tutorials out there. If you then have specific problems with your code, feel free to update your question with the details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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