useSignUpWithEmailAndPassword
Overview
The useSignUpWithEmailAndPassword
hook enables you to securely sign up a user with their email and password. It ensures sensitive data is encrypted using a public key, which is retrieved via the usePublicKey
hook. This hook integrates with Replyke’s authentication system and returns access tokens, refresh tokens, and user details upon successful registration.
Usage Example
import { useSignUpWithEmailAndPassword, usePublicKey } from "@replyke/react-js";
function SignUpForm() {
const signUp = useSignUpWithEmailAndPassword();
const publicKey = usePublicKey();
const handleSignUp = async () => {
try {
const result = await signUp({
publicKeyBase64: publicKey,
email: "[email protected]",
password: "securePassword123",
name: "John Doe",
username: "johndoe",
avatar: "https://example.com/avatar.jpg",
bio: "Just another user",
location: { latitude: 40.7128, longitude: -74.0060 },
birthdate: new Date("1990-01-01"),
metadata: { favoriteColor: "blue" },
secureMetadata: { ssn: "123-45-6789" },
});
console.log("User registered:", result.user);
} catch (error) {
console.error("Sign-up failed:", error.message);
}
};
return <button onClick={handleSignUp}>Sign Up</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. |
name | string | No | The user’s full name. |
username | string | No | The user’s chosen username. |
avatar | string (URL) | No | URL to the user’s profile picture. |
bio | string | No | A short bio or description for the user. |
location | object | No | The user’s geographic location (latitude, longitude). |
birthdate | Date | No | The user’s birthdate. |
metadata | Record<string, any> | No | Custom metadata associated with the user. |
secureMetadata | Record<string, any> | No | Metadata about the user that should not be fetched when the user is referenced (e.g., in comments or entities). |
Returns
The returned function resolves with an object containing:
Property | Type | Description |
---|---|---|
accessToken | string | The access token for the newly created 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 registered user’s details. |