# TanStack Router (/docs/reference/tanstack-router)

```ts
import { … } from "@monarcode/session-kit/tanstack-router";
```

Guide: [TanStack Router](/docs/setups/tanstack-router).

## Functions [#functions]

### connectAuth [#connectauth]

Starts auth for a Router whose context holds the client as `auth`. It restores the session, runs expiry timers, follows other tabs, and runs guards such as `requireSession` again when the session changes. Call it once, beside the Router.

### redirectIfSignedIn [#redirectifsignedin]

Guards your sign-in page in `beforeLoad`, so a signed-in user goes straight to `redirectTo`, made safe with `safeReturnTo`.

### requireSession [#requiresession]

Guards a route in `beforeLoad`, so only signed-in users get through. They get `{ session }` in route context, typed and never `null`, with no tokens in it.

### useRouterAuth [#userouterauth]

Reads the auth client from Router context, where it's `auth`. Pass it to `createAuthHooks` as `useClient`, so the hooks need no `AuthProvider`. Then mount the client with `connectAuth`.

## Components [#components]

### SessionOutlet [#sessionoutlet]

Renders the child routes of a route guarded by `requireSession`, but only while the session it accepted is still the signed-in one.

## Types [#types]

### RedirectIfSignedInOptions [#redirectifsignedinoptions]

Options for [`redirectIfSignedIn`](#redirectifsignedin).

### RedirectIfSignedInOptions

Options for redirectIfSignedIn.

| Prop         | Type      | Description                                                                                              |
| ------------ | --------- | -------------------------------------------------------------------------------------------------------- |
| `redirectTo` | `unknown` | Where to send a signed-in user, usually the `redirectTo` search param. It's checked with `safeReturnTo`. |
| `loginPath?` | `union`   | Your sign-in page's path, or several. `redirectTo` never sends the user back to one. Default: `"/login"` |

### RegisteredAuth [#registeredauth]

The auth client type in your registered Router's context, which [`useRouterAuth`](#userouterauth) returns. It's `never` until the Router is registered.

### RequireSessionOptions [#requiresessionoptions]

Options for [`requireSession`](#requiresession).

### RequireSessionOptions

Options for requireSession.

| Prop        | Type     | Description                                                                                              |
| ----------- | -------- | -------------------------------------------------------------------------------------------------------- |
| `location`  | `object` | The route's location, from `beforeLoad`'s `location`. Signed-out users come back to it after signing in. |
| `loginPath` | `string` | Your sign-in page's path, starting with `/`, such as `"/login"`.                                         |

### SessionOutletProps [#sessionoutletprops]

Props for [`SessionOutlet`](#sessionoutlet).

### SessionOutletProps

Props for SessionOutlet.

| Prop       | Type         | Description                                                                                |
| ---------- | ------------ | ------------------------------------------------------------------------------------------ |
| `pending?` | `ReactNode`  | Shown while the guard checks the session again, such as after a sign-out.                  |
| `client?`  | `AuthSource` | The client to watch. Default: the nearest `AuthProvider`'s, then `auth` in Router context. |