React & React NativeHooksAuthenticationuseSignUpWithEmailAndPassword

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:

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.
namestringNoThe user’s full name.
usernamestringNoThe user’s chosen username.
avatarstring (URL)NoURL to the user’s profile picture.
biostringNoA short bio or description for the user.
locationobjectNoThe user’s geographic location (latitude, longitude).
birthdateDateNoThe user’s birthdate.
metadataRecord<string, any>NoCustom metadata associated with the user.
secureMetadataRecord<string, any>NoMetadata 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:

PropertyTypeDescription
accessTokenstringThe access token for the newly created 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 registered user’s details.