Skip to main content

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.

note

This method works only if email confirmation is enabled in your Version settingsAuthentication view of Studio.

  • If the email of the user has not been verified yet, this method will return an error object.
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.

tip

You can define the Redirect URL in your Version settingsAuthentication view of Studio.

http://localhost:3001/auth-redirect?access_token=at-0e55c6fa93ae4e8cb11b35&action=reset-pwd
note

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

1emailStringYesThe email address of the user who wants to reset the password.
2redirectURLStringYesThe 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.

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

1accessTokenStringYesThe access token that is retrieved from the redirect URL query string parameter.
2newPasswordStringYesThe 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.

note

This method works only if phone confirmation is enabled in your Version settingsAuthentication view of Studio.

  • If the phone number of the user has not been verified yet, this method will return an error object.
const phone = "+15555555555";

// Send reset password email
const { errors } = await agnost.auth.sendResetPwdCode(phone);
note

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

1phoneStringYesThe 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.

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

1phoneStringYesThe phone number of the user.
1codeStringYesThe SMS code that is sent to the phone of the user.
2newPasswordStringYesThe new password of the user.