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:
| Parameter | Type | Required | Description |
|---|---|---|---|
publicKeyBase64 | string | Yes | The Base64-encoded public key for encrypting sensitive data. Obtain this key using the usePublicKey hook. |
email | string | Yes | The user’s email address. |
password | string | Yes | The user’s password. |
Returns
The returned function resolves with an object containing:
| Property | Type | Description |
|---|---|---|
accessToken | string | The access token for the authenticated user. It should be stored in memory. |
refreshToken | string | The 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. |
user | object | The authenticated user’s details. |