The `@authdog/tanstack-start` SDK integrates Authdog with TanStack Start: a client provider plus server helpers that resolve the session inside server functions and exchange the sign-in token into HttpOnly cookies. It reads the [session](/docs/concepts/sessions-tokens) Authdog issues.

## Install

```bash
npm install @authdog/tanstack-start
```

Requires `@tanstack/react-start ^1` and React 18 or 19. Set `PK_AUTHDOG` (your `pk_...` key) on the server.

## Wrap the app

`AuthdogProvider` and `ReloadPage` capture the `?token=` from the sign-in redirect once the server has persisted the session:

```tsx
import { AuthdogProvider } from "@authdog/tanstack-start/client"

function RootLayout({ children }: { children: React.ReactNode }) {
  return <AuthdogProvider>{children}</AuthdogProvider>
}
```

## Resolve the session in a server function

`identityLoader()` returns a handler that verifies the session on the server and, on first sign-in, sets hardened HttpOnly cookies. Call it from a server function:

```ts
import { createServerFn } from "@tanstack/react-start"
import { getWebRequest } from "@tanstack/react-start/server"
import { identityLoader } from "@authdog/tanstack-start"

const loadIdentity = createServerFn({ method: "GET" }).handler(async () => {
  const request = getWebRequest()
  const response = await identityLoader()({ request })
  return response.json()
})
```

## Sign out

`logoutLoader` returns a 302 response that clears the session cookies:

```ts
import { logoutLoader } from "@authdog/tanstack-start"
export const logout = () => logoutLoader()
```

The server-resolved session is the enforcement point — pair it with your [authorization](/docs/concepts/authorization) model to decide what a user may do.

## Next steps

- [Component reference](/docs/components) — the `@authdog/react-elements` UI.
- [Backend requests](/docs/backend) — the verification model, in depth.
- [Quickstarts](/docs/quickstarts) — the five-minute path.
