簡體   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