Reset Password
Send reset password email
If your users are authenticated using their email and password, you can
send reset password email to a user by calling the sendResetPwdEmail
method.
This method works only if email confirmation is enabled in your Version settings → Authentication view of Studio.
- If the email of the user has not been verified yet, this method will return an error object.
- Javascript
const email = "[email protected]";
const redirectUrl = "http://localhost:3001/auth-redirect";
// Send reset password email
const { errors } = await agnost.auth.sendResetPwdEmail(email, redirectUrl);
When the user clicks on the link in email, Agnost verifies the validity of the reset-password link and if successful redirects the user to the Redirect URL with an access token in a query string parameter named access_token.
You can define the Redirect URL in your Version settings → Authentication view of Studio.
At this stage your app needs to detect action=reset-pwd
in the Redirect
URL and display a password reset form to the user.
After getting the new password from the user, you can call the resetPwdWithToken method with the access token and new password to reset the password of the user.
Parameters
Here you can find parameters for the sendResetPwdEmail
method.
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | String | Yes | The email address of the user who wants to reset the password. | |
2 | redirectURL | String | Yes | The URL that the user will be redirected after email is sent. |
Reset password with token
You can reset password of the user by calling the resetPwdWithToken
method. It
resets the password of the user by using the access token provided through the
sendResetPwdEmail method.
- Javascript
const accessToken = "at-0e55c6fa93ae4e8cb11b35";
const newPassword = "123456%";
// Reset password of the user with the `newPassword`
const { errors } = await agnost.auth.resetPwdWithToken(accessToken, newPassword);
Parameters
Here you can find parameters for the resetPwdWithToken
method.
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | accessToken | String | Yes | The access token that is retrieved from the redirect URL query string parameter. |
2 | newPassword | String | Yes | The new password of the user. |
Send reset password code
If your users are authenticated using their phone number and password,
you can send reset password SMS code to a user by calling the sendResetPwdCode
method.
This method works only if phone confirmation is enabled in your Version settings → Authentication view of Studio.
- If the phone number of the user has not been verified yet, this method will return an error object.
- Javascript
const phone = "+15555555555";
// Send reset password email
const { errors } = await agnost.auth.sendResetPwdCode(phone);
After sending the SMS code, you need to display a password reset form to the user. When you get the new password from the user, you can call resetPwdWithCode method with the phone number of the user, SMS code and new password.
Parameters
Here you can find parameters for the sendResetPwdCode
method.
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | phone | String | Yes | The phone number of the user who wants to reset the password. |
Reset password with code
You can reset password of the user by calling the resetPwdWithCode
method. It
resets the password of the user by using the SMS code provided through the
sendResetPwdCode method.
- Javascript
const phone = "+15555555555";
const code = "432987";
const newPassword = "123456%";
// Reset password of the user with the `newPassword`
const { errors } = await agnost.auth.resetPwdWithCode(phone, code, newPassword);
Parameters
Here you can find parameters for the resetPwdWithCode
method.
# | Name | Data type | Required | Description |
---|---|---|---|---|
1 | phone | String | Yes | The phone number of the user. |
1 | code | String | Yes | The SMS code that is sent to the phone of the user. |
2 | newPassword | String | Yes | The new password of the user. |