#45

Migrate Redakt to TanStack Start

MergedstylesshOwnermerged intofrom

Summary

  • replace Next.js completely with TanStack Start, TanStack Router, and TanStack Query
  • port public, authenticated, mail, settings, AI, and external API routes while preserving nested mailbox layouts
  • switch the production build, runtime, and container to Nitro output
  • add the completed migration plan and update project tooling and documentation

Validation

  • pnpm test (169 passed)
  • pnpm lint
  • pnpm typecheck
  • pnpm build
  • production Docker image build plus health and SSR inbox smoke tests
  • desktop and 390px browser QA across inbox, conversation, Focus, and settings with no browser errors
  • Next.js residue, lockfile, client-boundary, and diff-hygiene scans

Follow-up after merge candidate deployment

  • verify live Better Auth and Gmail OAuth against staging credentials
  • verify the staging health endpoint and production-like Railway rollout

Activity

4
mikeyreviewed2mo ago
mikey2mo ago

Review: Migrate Redakt to TanStack Start (#45)

Reviewed this as a framework port rather than a fresh feature: for every changed route/handler I diffed the old Next.js implementation against its new TanStack Start counterpart, with special attention to auth checks, ownership/tenant-scoping, and any place a check could be silently dropped during the port. I split the surface into four areas and verified each independently (checked out pr-45 @ c890860 against base 40b4a27 locally, read both sides of every pair, not just the diff hunks).

Auth & sessions (src/server/auth.server.ts, auth.functions.ts, lib/auth-core.ts, _authenticated layout guard, src/routes/api/auth/**, session revoke endpoints): Better Auth config is byte-for-byte preserved aside from swapping nextCookies() for tanstackStartCookies(). Every previously-protected page under app/mail/** has a matching file under src/routes/_authenticated/mail/** gated by the same beforeLoad session check, and every API handler still independently re-checks the session server-side. Session revoke endpoints still scope to the caller's own sessions only. The old proxy.ts middleware (cache headers + demo-sandbox cookie seeding) was reimplemented as requestMiddleware in src/start.ts, and a new CSRF middleware for server functions was added (net addition, not a regression).

Mail API (src/routes/api/mail/**, src/server/mail.functions.ts, mail-provider.server.ts): the single choke point for account/thread/attachment ownership, resolveMailAccount(user, accountId), is unchanged and still called before every mail operation. Google Pub/Sub webhook JWT verification (issuer/audience/service-account/email_verified) is byte-identical to the old route — no auth bypass introduced. Send/compose/draft validation preserved.

Settings & domains API (src/routes/api/settings/**, src/routes/api/domains*): password-change current-password check, domain ownership check (getUserDomain still rejects row.userId !== user.id), and session-revoke scoping all preserved. All six old settings endpoints have 1:1 new counterparts — nothing silently dropped.

Route tree / build / deploy (src/start.ts, vite.config.mts, Dockerfile, mailbox nested routes, tsconfig.json): no server secrets leak into the client bundle (a custom serverOnlyBoundary Vite plugin enforces this), Dockerfile correctly targets Nitro's .output layout instead of stale .next/standalone paths, and the accountId-scoped nested mailbox routes preserve the same nesting and redirect behavior as the old app/mail/a/[accountId]/** tree.

Non-blocking follow-up

  • src/routes/api/mail/threads/$id.ts (PATCH) dropped the old route's revalidateTag(mailAccountCacheTag(...), { expire: 0 }) call — that was Next.js-specific cache invalidation with no direct TanStack Start equivalent in the new code. Not a security issue, but if any server-side response caching still sits in front of thread/folder reads, a mutation could serve stale data until TTL expiry. Worth a quick check post-merge; not blocking.

No blocking correctness or security issues found. This PR is safe to merge from this pass.

stylessh merged commit 6b814ac into main2mo ago

Branch worktree-keen-indigo-valley has been merged.

Checking branch