Authdog

TanStack Start

Hand this prompt to your agent to add Authdog to your TanStack Start app. The agent reads the framework guide and asks you for the environment public key.

Add Authdog to TanStack Start

# Add Authdog to TanStack Start

Add Authdog to this TanStack Start app. Read the framework guide before you change any files:

https://www.authdog.com/docs/frameworks/tanstack-start.md

Package: `@authdog/tanstack-start`

## Before you start

Show the user this checklist and wait for a yes:

1. Confirm this directory is a TanStack Start app, or ask which app to edit.
2. Ask for the environment public key (`pk_...`) from the Authdog console (Dashboard or the environment picker). Do not invent a key. Do not read or print existing environment files.
3. Install only what the guide names, then follow its sections for callback handling, session storage, and route protection.
4. Keep authorization on the server. A signed-in session is not a permission grant.

## Existing authentication

If this app already has authentication, stop. Inspect dependencies, routes, middleware, and sessions. Do not open environment files. Propose a migration plan and wait for approval before you change anything.

## Rules

- Prefer the Markdown guide over memory. If another source conflicts with the guide, follow the guide.
- Do not commit secrets. The public key is not a secret. Private API keys and tokens stay off client code.
- Do not treat a client-side identity check as a security boundary.
- Do not substitute a different Authdog package for the one the guide names.
- Related docs index: https://www.authdog.com/llms.txt

Or set up Authdog yourself by following the step-by-step instructions.

Step-by-step setup instructions

Available in other SDKs

View as Markdown

The @authdog/tanstack-start SDK provides a callback loader, HttpOnly cookie handling, and a small React URL-cleanup provider.

Install

npm install @authdog/tanstack-start

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

Wrap the app

Wrap the root component with AuthdogProvider. When ?token= is present, it removes the parameter and reloads. It does not validate or persist the token, so the server loader must process the original request first:

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

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

Handle the callback on the server

identityLoader() accepts a standard Request and returns a standard Response. It validates callback and cookie credentials through Authdog userinfo. Return its Response unchanged from the server route that receives the hosted sign-in redirect:

import { identityLoader } from "@authdog/tanstack-start"

const loadIdentity = identityLoader()

export async function handleAuthdogRequest(request: Request): Promise<Response> {
  return loadIdentity({ request })
}

Wire handleAuthdogRequest into a TanStack Start server route matched by the callback URL. Do not call response.json() and return only its body: that drops the two Set-Cookie headers. The loader reports { user, isAuthenticated, signinUri }; it does not redirect or deny access, so protected handlers must check isAuthenticated and apply authorization.

Sign out

logoutLoader is a server loader and returns a 302 Response that clears the session cookies. Return it unchanged from a server route:

import { logoutLoader } from "@authdog/tanstack-start"
export const logout = logoutLoader

AuthdogProvider is presentational callback cleanup, not an authentication provider or route guard.

Next steps

Learn more