React & React NativeHooksAuthenticationuseSignUpWithEmailAndPassword

useSignUpWithEmailAndPassword

Overview

The useSignUpWithEmailAndPassword hook enables you to securely sign up a user with their email and password. This hook integrates with Replyke’s authentication system and returns access token, refresh token, and user details upon successful registration.

Usage Example

import { useSignUpWithEmailAndPassword } from "@replyke/react-js";
 
function SignUpForm() {
  const signUp = useSignUpWithEmailAndPassword();
 
  const handleSignUp = async () => {
    try {
      const result = await signUp({
        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
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 would 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.