useUser()
The useUser() hook exposes the primary User data construct, facilitating access to profile parameters, associated email identifiers, and custom public metadata attributes. Additionally, the hook provides the interface methods necessary to mutate user parameters dynamically from the client application.
Hook Import
import { useUser } from "@wacht/tanstack-router" ;
Hook Interface
Indicates whether the SDK is actively executing a network request to synchronize the user identity context.
user
CurrentUser & { refetch: () => void } | null
The active CurrentUser construct, alongside a refetch method to force invalidation. If the underlying session is unauthenticated, this property evaluates to null.
Captures network failures or processing exceptions encountered during the fetch operation.
Show Profile Modification Interface
updateProfile
(data: ProfileUpdateData) => Promise<ApiResult<CurrentUser>>
Show Modify User Attributes
The subset of profile attributes designated for modification.
returns
Promise<ApiResult<CurrentUser>>
Resolves with the serialized updated user construct.
updateProfilePicture
(file: File) => Promise<ApiResult<unknown>>
Show Modify Profile Asset
The binary representation of the image asset.
returns
Promise<ApiResult<unknown>>
Resolves upon successful upload and processing of the profile asset.
updatePassword
(currentPassword: string, newPassword: string) => Promise<ApiResult<unknown>>
Show Modify Credential Vector
The user’s current validation credential.
The newly designated validation credential.
returns
Promise<ApiResult<unknown>>
Resolves upon successful credential modification payload processing.
removePassword
(currentPassword: string) => Promise<ApiResult<unknown>>
Show Remove Credential Vector
The user’s current validation credential.
returns
Promise<ApiResult<unknown>>
Resolves upon successful credential invalidation and removal securely.
deleteAccount
(password: string) => Promise<ApiResult<unknown>>
The validation credential confirming intent.
returns
Promise<ApiResult<unknown>>
Resolves upon successful invocation of the account destruction process.
Email Identifier Operations
Show Email Verification Interface
getEmailAddresses
() => Promise<ApiResult<UserEmailAddress[]>>
Show Retrieve Identifier Scope
returns
Promise<ApiResult<UserEmailAddress[]>>
Returns an array detailing the email identifiers mapped to this user instance.
getEmailAddress
(id: string) => Promise<ApiResult<UserEmailAddress>>
Show Retrieve Specific Identifier
The system identifier of the target address record.
returns
Promise<ApiResult<UserEmailAddress>>
Resolves with the serialized details of the requested email record.
createEmailAddress
(email: string) => Promise<ApiResult<UserEmailAddress>>
Show Initialize Additional Identifier
The target address to append to the user sequence.
returns
Promise<ApiResult<UserEmailAddress>>
Resolves with the details of the newly instantiated unverified record.
deleteEmailAddress
(id: string) => Promise<ApiResult<unknown>>
Show Remove Defined Identifier
The system identifier of the address record designated for removal.
returns
Promise<ApiResult<unknown>>
Resolves upon successful extraction of the identity mapping.
prepareEmailVerification
(id: string) => Promise<ApiResult<unknown>>
Show Initiate Identifier Verification
The system identifier of the address to verify.
returns
Promise<ApiResult<unknown>>
Resolves upon transmission of the verification challenge matrix.
attemptEmailVerification
(id: string, otp: string) => Promise<ApiResult<unknown>>
Show Submit Verification Challenge
The system identifier of the address being verified.
The client-submitted challenge response sequence.
returns
Promise<ApiResult<unknown>>
Resolves upon successful backend validation of the identity tie.
makeEmailPrimary
(id: string) => Promise<ApiResult<unknown>>
Show Promote Primary Identifier
The system identifier of the address to designate as root.
returns
Promise<ApiResult<unknown>>
Resolves upon modification of the user routing rules logic.
Phone Identifier Operations
Show Phone Verification Interface
createPhoneNumber
(phone_number: string, country_code: string) => Promise<ApiResult<UserPhoneNumber>>
Show Initialize Telephony Identifier
The telephony address to append.
The internationally defined prefix zone mapping.
returns
Promise<ApiResult<UserPhoneNumber>>
Resolves with the unverified record parameters.
deletePhoneNumber
(id: string) => Promise<ApiResult<unknown>>
Show Remove Telephony Identifier
The system identifier mapping to the configured record.
returns
Promise<ApiResult<unknown>>
Resolves upon successful separation of the identifier mapping.
preparePhoneVerification
(id: string) => Promise<ApiResult<unknown>>
Show Initiate Telephony Verification
returns
Promise<ApiResult<unknown>>
Resolves upon transmission of the SMS verification sequence.
attemptPhoneVerification
(id: string, otp: string) => Promise<ApiResult<unknown>>
Show Submit Telephony Challenge
The client-provided challenge parameter response.
returns
Promise<ApiResult<unknown>>
Resolves upon successful validation matching the generated backend sequence.
makePhonePrimary
(id: string) => Promise<ApiResult<unknown>>
Show Promote Primary Telephony Identifier
returns
Promise<ApiResult<unknown>>
Resolves upon mapping update logic.
Multi-Factor (TOTP) Operations
Show TOTP Authenticator Interface
setupAuthenticator
() => Promise<ApiResult<UserAuthenticator>>
Show Initialize TOTP Profile
returns
Promise<ApiResult<UserAuthenticator>>
Resolves with the cryptographic seed material and URI definitions mapping the initialization vector.
verifyAuthenticator
(id: string, codes: string[]) => Promise<ApiResult<unknown>>
Show Validate TOTP Interlock
The designated identification string.
An initial set of validity codes demonstrating time-aligned configuration.
returns
Promise<ApiResult<unknown>>
Resolves linking the validation logic upon sequence confirmation natively.
deleteAuthenticator
(id: string) => Promise<ApiResult<unknown>>
Show Disconnect TOTP Factor
The target identifier payload to dismantle.
returns
Promise<ApiResult<unknown>>
Resolves on successful severing of the TOTP challenge logic logic.
Show Backup Sequence Recovery
generateBackupCodes
() => Promise<ApiResult<string[]>>
Show Initialize Recovery Block
returns
Promise<ApiResult<string[]>>
Returns an array representing the newly minted static backup code payloads natively mapping to configuration parameters natively.
regenerateBackupCodes
() => Promise<ApiResult<string[]>>
Show Cycle Recovery Block
returns
Promise<ApiResult<string[]>>
Replaces and returns a substitute backup code array sequence while revoking prior material allocations dynamically.
Provider & Passkey Implementations
Show Advanced Interface Connectors
connectSocialAccount
(params: { provider: string; redirectUri?: string }) => Promise<ApiResult<{ oauth_url: string }>>
Show Initialize Provider Handshake
The target authorization server (e.g., ‘google’).
Optional local domain callback URI mapped for validation processing context flows natively via processing.
returns
Promise<ApiResult<{ oauth_url: string }>>
Generates the specific URL sequence routing to the authorization provider interface natively mapping directly via redirect initialization sequence mapping payload securely natively locally directly natively locally directly natively locally natively.
getPasskeys
() => Promise<ApiResult<UserPasskey[]>>
Show Retrieve Security Keys
returns
Promise<ApiResult<UserPasskey[]>>
Resolves yielding active cryptographic key structures mapped dynamically natively locally natively.
Implementation Guidelines
Standard implementation architectures persist domain-specific configuration elements (such as UI preferences) inside the User Object’s publicMetadata envelope. These attributes are securely dispatched to the client context post-authentication sequence natively.
import { useUser } from "@wacht/tanstack-router" ;
export function InterfaceConfigurationManager () {
const { loading , user } = useUser ();
if ( loading || ! user ) return null ;
const currentRoleConstraint = user . publicMetadata . role_constraint as string | undefined ;
return (
< div className = "text-sm border border-gray-200 p-4 rounded bg-white" >
System rendering mapping block identifier sequence string logic dynamically resolving parameter locally explicitly:
< span className = "font-semibold text-gray-900 ml-2" >
{ currentRoleConstraint || "UNASSIGNED_LOGIC_BLOCK_FALLBACK_DEFAULT" }
</ span >
</ div >
);
}
Mutating Account Properties
Attributes allocated to the user reference natively supply binding logic for direct remote record modification mapping parameters effectively directly matching specific requirements effectively effectively explicit sequence logic mappings implicitly updating contexts iteratively updating records securely.
import { useUser } from "@wacht/tanstack-router" ;
export function ModifySequenceComponent () {
const { user } = useUser ();
const handleUpdateTransaction = async () => {
if ( ! user ) return ;
try {
await user . update ({ firstName: "Jonathan" });
} catch ( err ) {
console . error ( "Mutation modification constraint enforcement triggered exception: " , err );
}
};
return (
< button onClick = { handleUpdateTransaction } className = "border p-2 bg-gray-50 uppercase text-xs" >
Submit Modification Sequence
</ button >
);
}