# useUser()

The `useUser()` hook provides access to the current user's [User](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md) object, which contains all the data for a single user in your application and provides methods to manage their account. This hook also allows you to check if the user is signed in and if Clerk has loaded and initialized.

## Returns

There are multiple variants of this type available which you can select by clicking on one of the tabs.

**Loading**

| Name         | Type        | Description                                                                                                                                                                                                                                                                                                                       |
| ------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isLoaded`   | `false`     | Indicates whether Clerk has loaded the current authentication state. Initially `false`, becomes `true` once Clerk loads, and can revert to `false` while auth state is updating (for example, when switching organizations via [setActive()](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#set-active)). |
| `isSignedIn` | `undefined` | Indicates whether the user is signed in.                                                                                                                                                                                                                                                                                          |
| `user`       | `undefined` | The `User` object for the current user.                                                                                                                                                                                                                                                                                           |

**Signed out**

| Name         | Type    | Description                                                                                                                                                                                                                                                                                                                       |
| ------------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isLoaded`   | `true`  | Indicates whether Clerk has loaded the current authentication state. Initially `false`, becomes `true` once Clerk loads, and can revert to `false` while auth state is updating (for example, when switching organizations via [setActive()](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#set-active)). |
| `isSignedIn` | `false` | Indicates whether the user is signed in.                                                                                                                                                                                                                                                                                          |
| `user`       | `null`  | The `User` object for the current user.                                                                                                                                                                                                                                                                                           |

**Signed in**

| Name         | Type                                                                                  | Description                                                                                                                                                                                                                                                                                                                       |
| ------------ | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isLoaded`   | `true`                                                                                | Indicates whether Clerk has loaded the current authentication state. Initially `false`, becomes `true` once Clerk loads, and can revert to `false` while auth state is updating (for example, when switching organizations via [setActive()](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#set-active)). |
| `isSignedIn` | `true`                                                                                | Indicates whether the user is signed in.                                                                                                                                                                                                                                                                                          |
| `user`       | [UserResource](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md) | The `User` object for the current user.                                                                                                                                                                                                                                                                                           |

## Examples

### Get the current user

The following example demonstrates how to use the [useUser()](https://clerk.com/docs/tanstack-react-start/reference/hooks/use-user.md) hook to access the [User](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md) object, which contains the current user's data such as their ID.

filename: app/routes/index.tsx
```tsx
import { useUser } from '@clerk/tanstack-react-start'
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
  component: Home,
})

export default function Home() {
  const { isSignedIn, user, isLoaded } = useUser()

  // Handle loading state
  if (!isLoaded) return <div>Loading...</div>

  // Protect the page from unauthenticated users
  if (!isSignedIn) return <div>Sign in to view this page</div>

  return <div>Hello {user.id}!</div>
}
```

### Update user data

The following example uses the `useUser()` hook to access the [User](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md) object, which calls the [update()](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md#update) method to update the current user's information.

filename: app/routes/index.tsx
```tsx
import { useUser } from '@clerk/tanstack-react-start'
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
  component: Home,
})

export default function Home() {
  const { isSignedIn, isLoaded, user } = useUser()

  // Handle loading state
  if (!isLoaded) return <div>Loading...</div>

  // Protect the page from unauthenticated users
  if (!isSignedIn) return <div>Sign in to view this page</div>

  const updateUser = async () => {
    await user.update({
      firstName: 'John',
      lastName: 'Doe',
    })
  }

  return (
    <>
      <button onClick={updateUser}>Update your name</button>
      <p>user.firstName: {user.firstName}</p>
      <p>user.lastName: {user.lastName}</p>
    </>
  )
}
```

### Reload user data

The following example uses the `useUser()` hook to access the [User](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md) object, which calls the [reload()](https://clerk.com/docs/tanstack-react-start/reference/objects/user.md#reload) method to get the latest user's information.

filename: app/routes/index.tsx
```tsx
import { useUser } from '@clerk/tanstack-react-start'
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/')({
  component: Home,
})

export default function Home() {
  const { isSignedIn, isLoaded, user } = useUser()

  // Handle loading state
  if (!isLoaded) return <div>Loading...</div>

  // Protect the page from unauthenticated users
  if (!isSignedIn) return <div>Sign in to view this page</div>

  const updateUser = async () => {
    // Update data via an API endpoint
    const updateMetadata = await fetch('/api/updateMetadata', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        role: 'admin',
      }),
    })

    // Check if the update was successful
    if ((await updateMetadata.json()).message !== 'success') {
      throw new Error('Error updating')
    }

    // If the update was successful, reload the user data
    await user.reload()
  }

  return (
    <>
      <button onClick={updateUser}>Update your metadata</button>
      <p>user role: {user.publicMetadata.role}</p>
    </>
  )
}
```

---

## Sitemap

[Overview of all docs pages](https://clerk.com/docs/llms.txt)
