# `useUser`

:::info
If using Next.js App Router, add `"use client"` at the top of the file.
:::

Access the current authenticated user and refresh authentication tokens.

## Usage

```tsx
import { useUser } from '@openfort/react';

function Profile() {
  const { user, linkedAccounts, isAuthenticated, isConnected, getAccessToken } = useUser();

  if (!isConnected) return <SignIn />;

  return (
    <div>
      <p>User ID: {user?.id}</p>
      <p>Email: {user?.email}</p>
      <p>Linked accounts: {linkedAccounts?.length}</p>
    </div>
  );
}
```

## Return type

```ts
type UseUserReturn = {
  // Current user object (from @openfort/openfort-js).
  user: User | null
  // Linked accounts associated with the user.
  linkedAccounts: UserAccount[]
  // True while initial auth state is being resolved.
  isLoading: boolean
  // Whether the user is logged in.
  isAuthenticated: boolean
  // Whether the user is authenticated and wallet is ready.
  isConnected: boolean
  // Returns the current access token.
  getAccessToken(): Promise<string | null>
  // Forces a token refresh.
  validateAndRefreshToken(): Promise<void>
}

// User type is imported from @openfort/openfort-js
type User = {
  id: string
  email?: string
  phoneNumber?: string
  createdAt?: string
  // ... additional user properties
}

// UserAccount is aliased from ListAccountsGet200ResponseInner in @openfort/openfort-js
type UserAccount = {
  provider: string
  createdAt: number
  updatedAt: number
  accountId: string
  chainType: string
  chainId: string
  connectorType: string
  walletClientType: string
}
```
