跳到主要内容

Passwords

Recover a forgotten password or change the password for a signed-in user.

备注

authInstanceESPRMAuth from Get auth instance. userInstance — from User sign in.

What This Module Does ?

Supports account recovery (verification code + new password) and in-session password change (old + new password).

Use forgot-password flows when the user is logged out. Use change password when the user is already signed in.

Expected outcome: Password updated in RainMaker; user can sign in with the new password.

Common Workflows

Forgot password

await authInstance.forgotPassword(username);
await authInstance.setNewPassword(username, newPassword, verificationCode);

Change password (signed in)

await userInstance.changePassword(oldPassword, newPassword);

Error Handling

try {
await authInstance.setNewPassword(username, newPassword, verificationCode);
} catch (error) {
console.error("Password reset failed:", error);
}

Verify the reset code before calling setNewPassword. For change password, ensure the old password is correct.

Best Practices

  1. Separate UI flows for forgot vs change password
  2. Clear local session after a successful reset if the user was partially logged in
  3. Validate password policy in your app before calling the SDK

On this page