Backend Flows
Auth lifecycle
- Supabase Auth handles email/password, OAuth (Google/GitHub), and magic links.
- Route:
/auth/callbackexchanges codes/token hashes, enforces recovery cookie for reset flow, redirects to dashboard ornextparam. - Middleware: redirects unauthenticated users from
/dashboard*; redirects authenticated users away from/sign-in|/sign-up|/forgot-password|/reset-passwordunless in recovery mode. - Server actions
(auth)/actions.ts: sign-in/up, magic link, OAuth redirect, reset email, reset password, sign-out; all rate-limited and sanitized errors.
Billing lifecycle
- Checkout:
/api/checkout_sessionsreceivespriceId(orprice_id), rate-limits by IP, maps to plan config, creates Stripe Checkout session with metadata{user_id?, plan_id, plan_type, price_id}. - Webhook:
/api/webhooks/stripeverifies signature withSTRIPE_WEBHOOK_SECRET, then:checkout.session.completed→ one-time purchase handler or subscription upsert.customer.subscription.created|updated|deleted→ upsertuser_subscriptions.invoice.payment_succeeded|failed→ insertpayment_history.payment_intent.succeededfor one-time → insertsone_time_purchases+payment_history.
- License & email: One-time purchase flow creates a license key and sends purchase confirmation via Resend (if email available/valid).
- Portal:
/api/customer_portal(GET/POST) creates Stripe portal session using storedstripe_customer_id.
Licensing & downloads
- License table ties a purchase to
plan_id, email, GitHub username (optional), download counts. /api/download: requires Supabase auth, checks active license and expiry, blocks Standard fromversion=latest, generates signed Storage URL, records download history and increments count via RPC.
GitHub collaborator access
/api/github-access(POST): requires auth + Ultimate license; validates username, calls GitHub API with PAT + repo envs, storesgithub_username, returns invitation status./api/github-access(GET): reports current collaborator or pending invitation state.
Analytics
- Server events tracked via
lib/posthog/server.ts(disabled in dev/missing key). - Checkout/webhook paths send subscription/purchase events with plan, billing cycle, amount, currency.
SEO & OG
- JSON-LD generators for site, organization, pages, articles.
- Dynamic OG images at
/api/og(site) and/api/og/blog(post title/author/date).