# useAuth()

The `useAuth()` hook provides access to the current user's authentication state and methods to manage the active session. You can use this hook to get the user's authentication and Organization information, like their ID, session ID, session token, Organization ID, and Organization Role, and to check if the user is authenticated or authorized to access a specific resource.

> To access auth data server-side, see the [`Auth` object reference doc](https://clerk.com/docs/reference/backend/types/auth-object.md?sdk=tanstack-react-start).

## Parameters

| Parameter  | Type                                                       | Description                                                                                                                                                                  |
| ---------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `options?` | `null | { treatPendingAsSignedOut?: boolean; }` | An object containing options for the `useAuth()` hook. `treatPendingAsSignedOut` indicates whether pending sessions are considered as signed out or not. Defaults to `true`. |

## Returns

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

**Loading**

| Name            | Type                                                                                                                                                | Description                                                                                                                                                                                                                                                                                                                       |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `actor`         | `undefined`                                                                                                                                         | The JWT actor for the session. Read more about [impersonation](https://clerk.com/docs/guides/users/impersonation.md?sdk=tanstack-react-start).                                                                                                                                                                                    |
| `getToken()`    | <code>(options?: GetTokenOptions) => Promise<null | string></code>                                                                                  | A function that retrieves the current user's session token or a custom JWT template. Returns a promise that resolves to the token. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md#get-token).                                                                                   |
| `has()`         | `(params: CheckAuthorizationParamsWithCustomPermissions) => false`                                                                       | A function that checks if the user has specific Permissions or Roles. See the [reference doc](https://clerk.com/docs/reference/backend/types/auth-object.md?sdk=tanstack-react-start#has).                                                                                                                                        |
| `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 a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `orgId`         | `undefined`                                                                                                                                         | The ID of the user's active Organization.                                                                                                                                                                                                                                                                                         |
| `orgRole`       | `undefined`                                                                                                                                         | The current user's Role in their active Organization.                                                                                                                                                                                                                                                                             |
| `orgSlug`       | `undefined`                                                                                                                                         | The URL-friendly identifier of the user's Active Organization.                                                                                                                                                                                                                                                                    |
| `sessionClaims` | `undefined`                                                                                                                                         | The current user's [session claims](https://clerk.com/docs/guides/sessions/session-tokens.md?sdk=tanstack-react-start).                                                                                                                                                                                                           |
| `sessionId`     | `undefined`                                                                                                                                         | The ID for the current session.                                                                                                                                                                                                                                                                                                   |
| `signOut()`     | <code>{ (options?: SignOutOptions): Promise<void>; (signOutCallback?: () => void | Promise<any>, options?: SignOutOptions): Promise<void>; }</code> | A function that signs out the current user. Returns a promise that resolves when complete. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#sign-out).                                                                                                                              |
| `userId`        | `undefined`                                                                                                                                         | The ID of the current user.                                                                                                                                                                                                                                                                                                       |

**Signed out**

| Name            | Type                                                                                                                                                | Description                                                                                                                                                                                                                                                                                                                       |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `actor`         | `null`                                                                                                                                              | The JWT actor for the session. Read more about [impersonation](https://clerk.com/docs/guides/users/impersonation.md?sdk=tanstack-react-start).                                                                                                                                                                                    |
| `getToken()`    | <code>(options?: GetTokenOptions) => Promise<null | string></code>                                                                                  | A function that retrieves the current user's session token or a custom JWT template. Returns a promise that resolves to the token. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md#get-token).                                                                                   |
| `has()`         | `(params: CheckAuthorizationParamsWithCustomPermissions) => false`                                                                       | A function that checks if the user has specific Permissions or Roles. See the [reference doc](https://clerk.com/docs/reference/backend/types/auth-object.md?sdk=tanstack-react-start#has).                                                                                                                                        |
| `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 a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `orgId`         | `null`                                                                                                                                              | The ID of the user's active Organization.                                                                                                                                                                                                                                                                                         |
| `orgRole`       | `null`                                                                                                                                              | The current user's Role in their active Organization.                                                                                                                                                                                                                                                                             |
| `orgSlug`       | `null`                                                                                                                                              | The URL-friendly identifier of the user's Active Organization.                                                                                                                                                                                                                                                                    |
| `sessionClaims` | `null`                                                                                                                                              | The current user's [session claims](https://clerk.com/docs/guides/sessions/session-tokens.md?sdk=tanstack-react-start).                                                                                                                                                                                                           |
| `sessionId`     | `null`                                                                                                                                              | The ID for the current session.                                                                                                                                                                                                                                                                                                   |
| `signOut()`     | <code>{ (options?: SignOutOptions): Promise<void>; (signOutCallback?: () => void | Promise<any>, options?: SignOutOptions): Promise<void>; }</code> | A function that signs out the current user. Returns a promise that resolves when complete. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#sign-out).                                                                                                                              |
| `userId`        | `null`                                                                                                                                              | The ID of the current user.                                                                                                                                                                                                                                                                                                       |

**Signed in (no active organization)**

| Name            | Type                                                                                                                                                | Description                                                                                                                                                                                                                                                                                                                       |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `actor`         | `null | { [x: string]: unknown; sub: string; type?: "agent"; }`                                                                          | The JWT actor for the session. Read more about [impersonation](https://clerk.com/docs/guides/users/impersonation.md?sdk=tanstack-react-start).                                                                                                                                                                                    |
| `actor.sub`     | `string`                                                                                                                                            | The identifier for the user that is impersonating the current user.                                                                                                                                                                                                                                                               |
| `actor.type?`   | `"agent"`                                                                                                                                           | The type of the actor.                                                                                                                                                                                                                                                                                                            |
| `getToken()`    | <code>(options?: GetTokenOptions) => Promise<null | string></code>                                                                                  | A function that retrieves the current user's session token or a custom JWT template. Returns a promise that resolves to the token. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md#get-token).                                                                                   |
| `has()`         | `(isAuthorizedParams: CheckAuthorizationParamsWithCustomPermissions) => boolean`                                                         | A function that checks if the user has specific Permissions or Roles. See the [reference doc](https://clerk.com/docs/reference/backend/types/auth-object.md?sdk=tanstack-react-start#has).                                                                                                                                        |
| `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 a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `orgId`         | `null`                                                                                                                                              | The ID of the user's active Organization.                                                                                                                                                                                                                                                                                         |
| `orgRole`       | `null`                                                                                                                                              | The current user's Role in their active Organization.                                                                                                                                                                                                                                                                             |
| `orgSlug`       | `null`                                                                                                                                              | The URL-friendly identifier of the user's Active Organization.                                                                                                                                                                                                                                                                    |
| `sessionClaims` | `JwtPayload`                                                                                                                                        | The current user's [session claims](https://clerk.com/docs/guides/sessions/session-tokens.md?sdk=tanstack-react-start).                                                                                                                                                                                                           |
| `sessionId`     | `string`                                                                                                                                            | The ID for the current session.                                                                                                                                                                                                                                                                                                   |
| `signOut()`     | <code>{ (options?: SignOutOptions): Promise<void>; (signOutCallback?: () => void | Promise<any>, options?: SignOutOptions): Promise<void>; }</code> | A function that signs out the current user. Returns a promise that resolves when complete. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#sign-out).                                                                                                                              |
| `userId`        | `string`                                                                                                                                            | The ID of the current user.                                                                                                                                                                                                                                                                                                       |

**Signed in (with active organization)**

| Name            | Type                                                                                                                                                | Description                                                                                                                                                                                                                                                                                                                       |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `actor`         | `null | { [x: string]: unknown; sub: string; type?: "agent"; }`                                                                          | The JWT actor for the session. Read more about [impersonation](https://clerk.com/docs/guides/users/impersonation.md?sdk=tanstack-react-start).                                                                                                                                                                                    |
| `actor.sub`     | `string`                                                                                                                                            | The identifier for the user that is impersonating the current user.                                                                                                                                                                                                                                                               |
| `actor.type?`   | `"agent"`                                                                                                                                           | The type of the actor.                                                                                                                                                                                                                                                                                                            |
| `getToken()`    | <code>(options?: GetTokenOptions) => Promise<null | string></code>                                                                                  | A function that retrieves the current user's session token or a custom JWT template. Returns a promise that resolves to the token. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md#get-token).                                                                                   |
| `has()`         | `(isAuthorizedParams: CheckAuthorizationParamsWithCustomPermissions) => boolean`                                                         | A function that checks if the user has specific Permissions or Roles. See the [reference doc](https://clerk.com/docs/reference/backend/types/auth-object.md?sdk=tanstack-react-start#has).                                                                                                                                        |
| `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 a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `orgId`         | `string`                                                                                                                                            | The ID of the user's active Organization.                                                                                                                                                                                                                                                                                         |
| `orgRole`       | `string`                                                                                                                                            | The current user's Role in their active Organization.                                                                                                                                                                                                                                                                             |
| `orgSlug`       | `null | string`                                                                                                                          | The URL-friendly identifier of the user's Active Organization.                                                                                                                                                                                                                                                                    |
| `sessionClaims` | `JwtPayload`                                                                                                                                        | The current user's [session claims](https://clerk.com/docs/guides/sessions/session-tokens.md?sdk=tanstack-react-start).                                                                                                                                                                                                           |
| `sessionId`     | `string`                                                                                                                                            | The ID for the current session.                                                                                                                                                                                                                                                                                                   |
| `signOut()`     | <code>{ (options?: SignOutOptions): Promise<void>; (signOutCallback?: () => void | Promise<any>, options?: SignOutOptions): Promise<void>; }</code> | A function that signs out the current user. Returns a promise that resolves when complete. See the [reference doc](https://clerk.com/docs/tanstack-react-start/reference/objects/clerk.md#sign-out).                                                                                                                              |
| `userId`        | `string`                                                                                                                                            | The ID of the current user.                                                                                                                                                                                                                                                                                                       |

## Example

The following example demonstrates how to use the `useAuth()` hook to access the current auth state, like whether the user is signed in or not. It also includes a basic example for using the `getToken()` method to retrieve a session token for fetching data from an external resource.

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

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

function ExternalDataPage() {
  const { userId, sessionId, getToken, isLoaded, isSignedIn } = useAuth()

  const fetchExternalData = async () => {
    const token = await getToken()

    // Fetch data from an external API
    const response = await fetch('https://api.example.com/data', {
      headers: {
        Authorization: `Bearer ${token}`,
      },
    })

    return response.json()
  }

  // 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>
      <p>
        Hello, {userId}! Your current active session is {sessionId}.
      </p>
      <button onClick={fetchExternalData}>Fetch Data</button>
    </div>
  )
}
```

---

## Sitemap

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