Skip to main content

useUser

The useUser hook provides methods for managing the current user’s profile, email addresses, phone numbers, passwords, and two-factor authentication settings.

Return Value

user
User | null
The current user object
loading
boolean
Whether user data is loading
error
Error | null
Any error that occurred
refetch
updateProfile
getEmailAddresses
getEmailAddress
createEmailAddress
deleteEmailAddress
prepareEmailVerification
attemptEmailVerification
makeEmailPrimary
createPhoneNumber
deletePhoneNumber
preparePhoneVerification
attemptPhoneVerification
makePhonePrimary
updatePassword
removePassword
deleteAccount
connectSocialAccount
disconnectSocialConnection
getPasskeys
registerPasskey
deletePasskey
renamePasskey
setupAuthenticator
verifyAuthenticator
deleteAuthenticator
generateBackupCodes
regenerateBackupCodes
updateProfilePicture

Profile Management

updateProfile

Update the user’s profile information.
first_name
string
New first name
last_name
string
New last name
username
string
New username
profile_picture_url
string
URL to profile picture
await updateProfile({
  first_name: "Jane",
  last_name: "Doe",
  username: "janedoe",
});

Email Management

createEmailAddress

Add a new email address to the user account.
email
string
required
The email address to add
await createEmailAddress("new@example.com");

deleteEmailAddress

Remove an email address from the user account.
id
string
required
The ID of the email address to remove

prepareEmailVerification

Send a verification code to the specified email address.
id
string
required
The ID of the email address to verify

attemptEmailVerification

Verify an email address with an OTP code.
id
string
required
The ID of the email address to verify
otp
string
required
The OTP verification code
// Send verification code
await prepareEmailVerification("email_id_123");

// Submit verification code
await attemptEmailVerification("email_id_123", "123456");

Phone Management

createPhoneNumber

Add a new phone number to the user account.
phone_number
string
required
The phone number in E.164 format
country_code
string
required
The ISO country code (e.g., “US”)
await createPhoneNumber("+1234567890", "US");

deletePhoneNumber

Remove a phone number from the user account.
id
string
required
The ID of the phone number to remove

preparePhoneVerification

Send a verification code to the specified phone number.
id
string
required
The ID of the phone number to verify

attemptPhoneVerification

Verify a phone number with an OTP code.
id
string
required
The ID of the phone number to verify
otp
string
required
The OTP verification code
// Send verification code
await preparePhoneVerification("phone_id_123");

// Submit verification code
await attemptPhoneVerification("phone_id_123", "123456");

makePhonePrimary

Set a phone number as the primary phone number for the account.
id
string
required
The ID of the phone number to set as primary

makeEmailPrimary

Set an email address as the primary email address for the account.
id
string
required
The ID of the email address to set as primary

Password Management

updatePassword

Change the user’s password.
currentPassword
string
required
The current password
newPassword
string
required
The new password
await updatePassword("oldPassword123", "newPassword456");

removePassword

Remove the user’s password. After removal, the user can only sign in with passkeys or OAuth.
currentPassword
string
required
The current password (required to confirm removal)
await removePassword("currentPassword123");

deleteAccount

Delete the user’s account permanently.
password
string
required
The current password (required to confirm deletion)
await deleteAccount("currentPassword123");

Passkey Management

registerPasskey

Register a new passkey for the user using WebAuthn. The name parameter is optional.
await registerPasskey("My MacBook Pro");
// or without a name
await registerPasskey();

deletePasskey

Remove a passkey from the user account.
id
string
required
The ID of the passkey to remove

renamePasskey

Rename a passkey for easier identification.
id
string
required
The ID of the passkey to rename
name
string
required
The new name for the passkey
await renamePasskey("passkey_id_123", "My Work Laptop");

getPasskeys

Get all passkeys registered to the user account.
const passkeys = await getPasskeys();

Profile Picture

updateProfilePicture

Update the user’s profile picture.
file
File
required
The image file to upload
await updateProfilePicture(fileInput.files[0]);

Social Connections

connectSocialAccount

Connect a social account (OAuth provider) to the user account.
provider
string
required
The OAuth provider (e.g., “google_oauth”, “github_oauth”)
redirectUri
string
Optional redirect URI after OAuth flow
await connectSocialAccount({ provider: "google_oauth" });

disconnectSocialConnection

Disconnect a social account from the user account.
id
string
required
The ID of the social connection to remove
await disconnectSocialConnection("connection_id_123");

Two-Factor Authentication

setupAuthenticator

Begin TOTP authenticator setup. Returns a QR code URI and secret key.
const authenticator = await setupAuthenticator();
// authenticator contains: id, uri (for QR code), secret

verifyAuthenticator

Complete TOTP setup with verification codes.
id
string
required
The authenticator ID
codes
string[]
required
Array of 6-digit TOTP codes
await verifyAuthenticator("authenticator_id", ["123456", "234567"]);

deleteAuthenticator

Remove TOTP authenticator from the user account.
await deleteAuthenticator("authenticator_id");

generateBackupCodes

Generate backup codes for 2FA recovery.
const codes = await generateBackupCodes();
// Save these codes securely

regenerateBackupCodes

Regenerate backup codes (invalidates old ones).
const newCodes = await regenerateBackupCodes();