useChangePassword

Overview

The useChangePassword hook allows users to securely change their password. It encrypts the email, current password, and new password using a public key to ensure that sensitive data is transmitted securely.

Usage Example

import { useChangePassword, usePublicKey } from "@replyke/react-js";
 
function ChangePasswordForm() {
  const changePassword = useChangePassword();
  const publicKey = usePublicKey();
 
  const handleChangePassword = async () => {
    try {
      await changePassword({
        publicKeyBase64: publicKey,
        email: "[email protected]",
        password: "currentPassword123",
        newPassword: "newSecurePassword456",
      });
 
      console.log("Password changed successfully");
    } catch (error) {
      console.error("Failed to change password:", error.message);
    }
  };
 
  return <button onClick={handleChangePassword}>Change Password</button>;
}

Parameters & Returns

Parameters

The hook returns a function that accepts an object with the following fields:

ParameterTypeRequiredDescription
publicKeyBase64stringYesThe Base64-encoded public key for encrypting sensitive data. Obtain this key using the usePublicKey hook.
emailstringYesThe user’s email address.
passwordstringYesThe user’s current password.
newPasswordstringYesThe user’s new password.

Returns

The function does not return a value but ensures the password is updated on the server upon successful execution.