HelloJohn / docs
SDKsReact SDK

useUser

React hook for accessing and updating the current user's profile — name, email, metadata, and MFA status with the HelloJohn React SDK.

useUser

The useUser hook provides access to the current user's profile and methods to update it.

import { useUser } from "@hellojohn/react";

const { user, isLoading, updateUser } = useUser();

Return Value

PropertyTypeDescription
userUser | nullCurrent user object, or null if not authenticated
isLoadingbooleantrue on initial load
updateUser(data: UpdateUserInput) => Promise<{ error }>Update user profile

User Object

interface User {
  id: string;
  email: string;
  emailVerified: boolean;
  firstName: string | null;
  lastName: string | null;
  name: string | null;           // firstName + lastName
  avatarUrl: string | null;
  phoneNumber: string | null;
  phoneVerified: boolean;
  metadata: Record<string, unknown>;
  mfaFactors: MFAFactor[];
  oauthConnections: OAuthConnection[];
  createdAt: Date;
  updatedAt: Date;
  lastSignInAt: Date | null;
}

Usage

Display User Profile

import { useUser } from "@hellojohn/react";

function Profile() {
  const { user, isLoading } = useUser();

  if (isLoading) return <Spinner />;
  if (!user) return null;

  return (
    <div>
      <img src={user.avatarUrl ?? "/default-avatar.png"} alt="Avatar" />
      <h1>{user.name ?? user.email}</h1>
      <p>{user.email} {user.emailVerified ? "✅" : "(unverified)"}</p>
    </div>
  );
}

Update User Profile

import { useUser } from "@hellojohn/react";
import { useState } from "react";

function EditProfile() {
  const { user, updateUser } = useUser();
  const [error, setError] = useState<string | null>(null);

  async function handleSave(data: { firstName: string; lastName: string }) {
    const { error } = await updateUser(data);
    if (error) setError(error.message);
  }

  // ...
}

updateUser Parameters

ParameterTypeDescription
firstNamestringUpdated first name
lastNamestringUpdated last name
emailstringNew email (triggers re-verification)
phoneNumberstringPhone number
avatarUrlstringAvatar image URL
metadataobjectCustom metadata (merged with existing)
currentPasswordstringRequired when changing email or password
newPasswordstringNew password

Access Custom Metadata

Store and retrieve application-specific data on the user:

// Read metadata
const plan = user?.metadata?.plan as string;
const onboardingComplete = user?.metadata?.onboardingComplete as boolean;

// Update metadata (merged, not replaced)
await updateUser({
  metadata: {
    onboardingComplete: true,
    preferredLanguage: "en",
  },
});

Check MFA Status

const { user } = useUser();

const hasMFA = user?.mfaFactors.length > 0;
const hasTOTP = user?.mfaFactors.some(f => f.type === "totp");
const hasPasskey = user?.mfaFactors.some(f => f.type === "passkey");

On this page