Install with AI
Pick your setup. Paste the prompt into Claude Code, Cursor or any agent that reads URLs and edits files.
install.md
# Add login to this app with @kaarel/auth
Read https://auth.kaarel.dev/llms-full.txt first. It has the whole API. After install, also read node_modules/@kaarel/auth/AGENTS.md.
Framework: TanStack Start. Database: PostgreSQL, Bun built-in (DATABASE_URL).
## Steps
1. Install `@kaarel/auth`.
2. Create the auth config in a server-only module that fits this app's layout (for example `src/auth.ts` or `lib/auth.ts`). Call `createAuth({ ... })` with:
- `url: process.env.BASE_URL`, `secret: process.env.AUTH_SECRET`
- `db: process.env.DATABASE_URL` (this works on the Bun runtime only).
- `methods: [password(), google(process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_SECRET)]`
- `email: { from: "<App> <no-reply@<domain>>", send: resend(process.env.RESEND_API_KEY) }`
- `pages` with the real paths of the pages below
- Set `framework: tanstackStart()` (import from "@kaarel/auth/tanstack").
3. Mount `auth.routes` on a catch-all server route for `/auth/$`: `createFileRoute("/auth/$")({ server: { handlers: auth.routes } })`. On TanStack Start 1.131 use `createServerFileRoute("/auth/$").methods(auth.routes)`.
4. Call the package from server functions. Every server function that changes something uses `createServerFn({ method: "POST" })`. Do not name any file `src/server.ts`; TanStack Start uses that name for its server entry.
5. Build these pages in this app's own style and language: login (e-mail and password form, handles `?error=`, `?verified=1` and `?next=`); sign-up (shows "check your inbox" when `next` is `verify_email`); forgot password (`auth.password.requestReset`); new password at `pages.resetPassword` (`auth.password.reset` with `?token=`).
6. Protect signed-in routes with `beforeLoad` that calls a server function returning `auth.user()`, and redirects to the login page with `next` when it is null.
7. Add a settings page with: change password (`auth.account.changePassword`); active sessions with "sign out other devices" (`auth.sessions.list`, `revokeOthers`); connected accounts (links to `/auth/<provider>?link=1&next=<settings path>`, `auth.account.unlink`).
8. Add `AUTH_SECRET`, `BASE_URL`, `DATABASE_URL`, `RESEND_API_KEY`, `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` to the env example file.
9. Run `bunx --bun kaarel-auth doctor` and fix what it reports. Tell me the redirect URIs it prints.
## Rules
- Show every `AuthError` a call can return, in the app's own words. Pages import `AuthError` and `messages` from `@kaarel/auth/errors`; never import `@kaarel/auth` into browser code.
- Handle `reauth_required`: ask for the password and call `auth.account.reauthenticate({ password })`, then retry.
- Use `result.redirectTo` after sign-in and after the two-factor step.
- Do not add a client SDK or any other auth package. Do not write session or cookie code by hand. Do not render pages from the auth package.
The prompt sends the agent to /llms-full.txt, which has every docs page in one file. More in the Install with AI docs.