NERO
React SDKHooks

useNeroUser

Access user profile, manage devices, MFA, and account settings

useNeroUser

This page covers the useNeroProfile and useNeroMFA hooks, which provide access to user profile data, device management, multi-factor authentication, and account security settings.

useNeroProfile

State Properties

PropertyTypeDescription
profileUserProfile | nullCurrent user profile object
isLoadingbooleantrue during profile operations
errorError | nullError state for profile-related failures

Profile Management Methods

MethodParametersReturn TypePurpose
getProfile()--Promise<{ profile: UserProfile }>Fetches and caches user profile
updateProfile()data: { displayName?, profilePicture? }Promise<{ profile: Partial<UserProfile> }>Updates profile metadata
deleteAccount()confirmation: string, password?: stringPromise<{ message: string }>Permanently deletes account
getActivity()params?: { page?, limit?, action?, from?, to? }Promise<{ activities: ActivityEntry[], pagination }>Retrieves paginated audit logs
exportData()format?, includeWallet?Promise<Record<string, unknown>>Exports user data for GDPR/portability

Device Management Methods

MethodParametersPurpose
getDevices()--Returns array of TrustedDevice objects
trustDevice()deviceId: string, deviceName?: stringMarks a device as trusted
removeDevice()deviceId: stringRevokes trust and session for a device

Usage

import { useNeroProfile } from "@nerochain/mpc-sdk/react";

function Profile() {
  const { profile, getProfile, updateProfile, isLoading, error } = useNeroProfile();

  useEffect(() => {
    getProfile();
  }, []);

  if (isLoading) return <div>Loading...</div>;
  if (!profile) return <div>Not logged in</div>;

  return (
    <div>
      <p>Name: {profile.displayName}</p>
      <button onClick={() => updateProfile({ displayName: "New Name" })}>
        Update Name
      </button>
    </div>
  );
}

Device Management Example

function DeviceManager() {
  const { getDevices, removeDevice } = useNeroProfile();
  const [devices, setDevices] = useState([]);

  useEffect(() => {
    getDevices().then(setDevices);
  }, []);

  return (
    <ul>
      {devices.map((device) => (
        <li key={device.id}>
          {device.name}
          <button onClick={() => removeDevice(device.id)}>Remove</button>
        </li>
      ))}
    </ul>
  );
}

useNeroMFA

Manages multi-factor authentication configuration, supporting TOTP (authenticator apps) and WebAuthn (passkeys/biometrics).

State Properties

PropertyTypeDescription
statusMFAStatus | nullActive MFA methods and policy
isLoadingbooleantrue during MFA operations
errorError | nullLast encountered error

TOTP Methods

MethodParametersPurpose
initiateTOTPSetup()--Initiates TOTP enrollment, returns shared secret
verifyTOTPSetup()code: stringVerifies TOTP code to finalize setup
disableTOTP()--Removes TOTP authentication method

WebAuthn Methods

MethodParametersPurpose
initiateWebAuthnSetup()--Starts WebAuthn enrollment
verifyWebAuthnSetup()credentialConfirms WebAuthn credential
disableWebAuthn()--Removes WebAuthn method

Status and Verification

MethodParametersPurpose
getMFAStatus()--Retrieves current MFA configuration
verifyMFA()method: string, code: stringVerifies MFA challenge response

TOTP Setup Sequence

TOTP enrollment requires two steps:

  1. Call initiateTOTPSetup() to obtain the shared secret and QR code
  2. Call verifyTOTPSetup() with the generated code to confirm
function TOTPSetup() {
  const { initiateTOTPSetup, verifyTOTPSetup, isLoading } = useNeroMFA();
  const [secret, setSecret] = useState(null);
  const [code, setCode] = useState("");

  const handleSetup = async () => {
    const result = await initiateTOTPSetup();
    setSecret(result);
  };

  const handleVerify = async () => {
    await verifyTOTPSetup(code);
  };

  if (!secret) {
    return <button onClick={handleSetup} disabled={isLoading}>Enable TOTP</button>;
  }

  return (
    <div>
      <p>Scan the QR code with your authenticator app</p>
      <input value={code} onChange={(e) => setCode(e.target.value)} placeholder="Enter code" />
      <button onClick={handleVerify} disabled={isLoading}>Verify</button>
    </div>
  );
}

On this page