Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

useUser

Access the current authenticated user and refresh authentication tokens.

Usage

import { useUser } from '@openfort/react';
 
function Profile() {
  const { user, linkedAccounts, isAuthenticated, getAccessToken } = useUser();
 
  if (!isAuthenticated) return <SignIn />;
 
  return (
    <div>
      <p>User ID: {user?.id}</p>
      <p>Email: {linkedAccounts?.find(a => a.provider === 'email')?.email}</p>
    </div>
  );
}

Return type

type UseUserReturn = {
  // Current user object (from @openfort/openfort-js).
  user: User | null
  // Linked accounts associated with the user.
  linkedAccounts: LinkedAccountResponse[] | undefined
  // Whether the user is logged in.
  isAuthenticated: boolean
  // Returns the current access token.
  getAccessToken(): Promise<string | undefined>
  // Forces a token refresh.
  validateAndRefreshToken(): Promise<void>
}
 
// User type is imported from @openfort/openfort-js
type User = {
  id: string
  email?: string
  phone?: string
  createdAt?: number
  // ... additional user properties
}
 
type LinkedAccountResponse = {
  // Authentication provider.
  provider: AuthProviderResponse
  email?: string
  externalUserId?: string
  connectorType?: string
  // Wallet client identifier such as "metamask", "rabby", or "walletconnect".
  walletClientType?: string
  // Whether the linked account is disabled.
  disabled: boolean
  // Whether the email or account is verified.
  verified?: boolean
  updatedAt?: number
  // Blockchain address for wallet providers.
  accountId?: string
  metadata?: Record<string, PlayerMetadataValue>
}
 
type AuthProviderResponse =
  | 'email'
  | 'wallet'
  | 'google'
  | 'apple'
  | 'twitter'
  | 'discord'
  | 'epic_games'
  | 'facebook'
  | 'accelbyte'
  | 'firebase'
  | 'lootlocker'
  | 'playfab'
  | 'supabase'
  | 'custom'
  | 'oidc'
Copyright © 2023-present Alamas Labs, Inc