React & React NativeHooksAuthenticationuseSignInWithEmailAndPassword

useSignInWithEmailAndPassword

Overview

The useSignInWithEmailAndPassword hook allows users to securely sign in with their email and password. It encrypts sensitive data using a public key retrieved from the usePublicKey hook and integrates with Replyke’s authentication system to return tokens and user details upon successful authentication.

Usage Example

import { useSignInWithEmailAndPassword, usePublicKey } from "@replyke/react-js";
 
function SignInForm() {
  const signIn = useSignInWithEmailAndPassword();
  const publicKey = usePublicKey();
 
  const handleSignIn = async () => {
    try {
      const result = await signIn({
        publicKeyBase64: publicKey,
        email: "user@example.com",
        password: "securePassword123",
      });
 
      console.log("User signed in:", result.user);
    } catch (error) {
      console.error("Sign-in failed:", error.message);
    }
  };
 
  return <button onClick={handleSignIn}>Sign In</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 password.

Returns

The returned function resolves with an object containing:

PropertyTypeDescription
accessTokenstringThe access token for the authenticated user. It should be stored in memory.
refreshTokenstringThe refresh token for the user session. React Native apps must store this securely, whereas React apps do not need to store it manually as it is managed via cookies.
userobjectThe authenticated user’s details.