forgotPassword
A very important feature is to add the forgot password option into your app. This method allows you to update the password of a user account if the user is not authenticated. We validate a user with phone authentication in this case. So just prompt user about the email account associated with the account, we will automatically send the verification code the phone number associated with the profile and after which you can submit a confirmation request.
Forgot password function accepts the following arguments
Name | Type | Description |
---|---|---|
string | a valid email address associated with profile of the user |
This method returns the following code in form of promise
PHONE-CODE-SENT
verification code sent to phone number and you use the confirmation method returned in the response of promise to verify the user.
DATA-INVALID
data format is invalid
AUTH-ACCOUNT-ALREADY-LOGGEDIN
a user is already logged in
PHONE-CODE-SENDING-FAILED
failed to send code to phone number
confirm(code)
After submitting forgot password request, we send a verification code to the phone number associated with user's accounts. As a result, we also return you a confirm function, so that you could proceed with the forgot password operation after prompting the user about the verification code and a new password.
This function receives a single argument as illustrated below
Name | Type | Description |
---|---|---|
code | string | six digit long numeric code |
password | string | should be minimum six character long |
Upon execution, this method returns the following code in form of promise
AUTH-PROFILE-UPDATED
password has been updated
PHONE-CODE-INVALID
verification code is invalid
PHONE-CODE-VERIFICATION-FAILED
failed to verify the verification code
DATA-INVALID
data format is invalid
AUTH-PROFILE-UPDATE-FAILED
failed to update the profile
Use of forgotPassword method has been illustrated in the example below
// Variable to hold the confirmForgotPassword
// method so that it could be used afterwards
var confirm = null;
// Get user data from the inputs and
// Submit request to the server
auth.forgotPassword(email).then((res) => {
// Got the response
// So checkout the response code
switch(res.code) {
case "PHONE-CODE-SENT":
// Verification code has been sent
confirm = res.confirm;
}
})
// After getting response from forgot password request
// Prompt the user about the verification code
// and submit it to server with the confirm method
confirm(code).then((res) => {
// Got the response
switch(res.code) {
case "AUTH-PROFILE-UPDATED":
// Password has been updated
}
});