Documentation
Quick guide to authentication, billing, credits, and deployment.
Getting started
TanStack Cloudflare SaaS ships with auth, billing, credits, referrals, and admin tooling on Cloudflare Workers.
1. Copy `.dev.example` to `.dev.vars` and fill secrets.
2. Run `pnpm d1:migrate:apply` then `pnpm dev`.
3. Sign in at `/en/login` and explore the user console.
Authentication
Better Auth powers magic link, password, and Google OAuth flows. Sessions are stored in D1 with the custom adapter in `src/lib/d1-adapter.ts`.
Billing
Stripe subscriptions sync through the Better Auth Stripe plugin. Webhooks update subscription state and grant credits on eligible plans.
Credits
Credits accrue from signup grants, subscriptions, credit packs, admin grants, and affiliate rewards. Tasks consume credits via the ledger in `CreditLedger`.
Referrals
Each user receives an invite code. Referral cookies attribute signups; rewards post when invitees subscribe.
Deploy to Cloudflare
See `docs/cloudflare-deployment.md` for D1, KV, R2, Stripe webhooks, cron jobs, and the production checklist.