跳到主要内容

Passwords

Password management in the @espressif/rainmaker-base-sdk allows users to recover forgotten passwords and change their existing passwords.

备注

The authInstance mentioned below refers to the ESPRMAuth instance obtained from ESPRMBase.getAuthInstance().

Forgot Password

The forgot password process enables users to recover their account by requesting a verification code. Once the code is received, users can reset their password.

Request Forgot Password

To initiate the forgot password process, use the forgotPassword method:

/*
- username: The username of existing user.
*/

try {
const response = await authInstance.forgotPassword(username);
console.log("Forgot password request sent successfully:", response);
} catch (error) {
console.error("Error requesting forgot password:", error);
}

Set New Password

After receiving the verification code, use the setNewPassword method to set a new password:

/*
- username: The username of existing user.
- verificationCode: The verification code sent to the user's username
- newPassword: The new password to set
*/

try {
const response = await authInstance.setNewPassword(
username,
newPassword,
verificationCode
);
console.log("Password updated successfully:", response);
} catch (error) {
console.error("Error updating password:", error);
}

Change Password

Change the user's password by providing their old password and a new password using the changePassword method.

备注

The userInstance mentioned below refers to the ESPRMUser instance obtained during User Sign in.

/*
- oldPassword: The user's current password.
- newPassword: The new password to set for the user.
*/

try {
const response = await userInstance.changePassword(oldPassword, newPassword);
console.log("Password changed successfully:", response);
} catch (error) {
console.error("Error changing password:", error);
}

On this page