molecule-core/canvas/src/app
Hongming Wang aedd3db697 feat(canvas): AuthGate — redirect anonymous users to cp login (Phase F close)
Wraps the canvas root so every tenant-subdomain request checks for a
valid session and bounces to app.moleculesai.app/cp/auth/login with a
return_to pointing back at the current URL. Local dev + vercel preview
URLs + apex pass through unchanged.

Files:
- canvas/src/lib/auth.ts: fetchSession() probes /cp/auth/me
  (credentials:include for cross-origin cookie); returns Session on 200,
  null on 401 (anonymous, no throw), throws on 5xx so transient
  outages don't leak the UI.
- canvas/src/lib/auth.ts: redirectToLogin() builds the cp login URL
  with window.location.href as return_to; CP's isSafeReturnTo check
  rejects cross-domain bounces.
- canvas/src/components/AuthGate.tsx: client component wrapping
  children. State machine: loading → authenticated | anonymous. In
  non-SaaS mode (no tenant slug) skips the gate entirely.
- canvas/src/app/layout.tsx: wraps the root body in <AuthGate>.

Tests: +6 auth.ts (200 / 401 null / 5xx throw / credentials:include /
redirectToLogin href + signup variant). Full suite 453 green (was 447).

Pairs with molecule-controlplane PR #16 (return_to cookie handshake
on the cp side).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 20:37:26 -07:00
..
__tests__ initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
globals.css fix(a11y): prefers-reduced-motion WCAG 2.3.3 compliance 2026-04-14 11:25:23 +00:00
icon.png chore: replace brand icon and add HANDOFF.md 2026-04-13 13:03:40 -07:00
layout.tsx feat(canvas): AuthGate — redirect anonymous users to cp login (Phase F close) 2026-04-14 20:37:26 -07:00
page.tsx initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00