Skip to main content

Overview

useUser is the primary hook for interacting with the currently authenticated user’s profile. It provides the user’s full data (as an AuthUser), loading and error states, an updateUser action, and derived suspension state (isSuspended / activeSuspension). Updates are applied optimistically — the UI reflects changes immediately, and reverts automatically if the server request fails.

Usage Example

Uploading an Avatar

Removing the Avatar

List the current file’s id in removeFileIds. It clears the user’s avatar file and deletes it.

Return Values

AuthUser | null
The authenticated user’s full profile. Returns null while loading or when no user is authenticated. See User data model.
boolean
true while the user’s profile is being fetched for the first time.
boolean
true while an updateUser call is in progress.
SublayError | null
The error if an updateUser call fails. null when there is no error. A SublayError.
boolean
true while the authenticated user has an active suspension. Derived from the user’s suspensions using the same effective definition as the server.
UserSuspension | null
The user’s effective (furthest-reaching) active suspension — one of user.suspensions ({ id, userId, reason, startDate, endDate, createdBy, createdAt, updatedAt }) — or null when they aren’t suspended. endDate: null means the suspension is indefinite. Bind a “suspended until X” banner or a disabled composer to this. See Suspensions.
(update: UpdateUserParams) => Promise<AuthUser>
Updates the authenticated user’s profile. Takes the changes alone, e.g. updateUser({ name }). Applies optimistic updates immediately and reverts on failure.A null field can’t travel with avatarFile or bannerFile (a multipart request): such an update throws before anything is sent, naming the field. Send the clear in a separate call without a file.
() => void
Clears the current error state.

Optimistic Updates

updateUser applies changes to local state before the server responds. This makes the UI feel instant. Fields that cannot be optimistically applied (file uploads, location, birthdate) wait for the server response. If the server returns an error, the hook automatically reverts the user state to its pre-update value.
File uploads (avatarFile, bannerFile) and removeFileIds are not applied optimistically: the new file fields are known only once the server answers.