# useSession()

The `useSession()` hook provides access to the current user's [Session](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md) object, as well as helpers for setting the active session.

## 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 a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `session`    | `undefined` | The current session for the 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 a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `session`    | `null`  | The current session for the 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` | `boolean`                                                                                           | Indicates whether a user is currently signed in.                                                                                                                                                                                                                                                                                  |
| `session`    | [SignedInSessionResource](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md) | The current session for the user.                                                                                                                                                                                                                                                                                                 |

## Example

### Access the `Session` object

The following example uses the [useSession()](https://clerk.com/docs/tanstack-react-start/reference/hooks/use-session.md) hook to access the [Session](https://clerk.com/docs/tanstack-react-start/reference/objects/session.md) object. The `Session` object is used to access the `lastActiveAt` property, which is a `Date` object used to show the time the session was last active.

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

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

function HomePage() {
  const { isLoaded, session, isSignedIn } = useSession()

  // 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>This session has been active since {session.lastActiveAt.toLocaleString()}</p>
    </div>
  )
}
```

---

## Sitemap

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