Skip to content

feat(cms): sign in to the Payload admin with a Lumen account (PX1) - #22

Merged
ruehowl merged 1 commit into
mainfrom
orun/PX-2-lumen-sign-in
Oct 28, 2026
Merged

ruehowl merged 1 commit into
mainfrom
orun/PX-2-lumen-sign-in

Conversation

@ruehowl

@ruehowl ruehowl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

PX1 of specs/epics/lumen-payload-console: the Payload admin's only sign-in is a Lumen account. It has no CMS passwords.

What changes

  • /admin shows a Lumen sign-in: an emailed code, or GitHub or Google where identity has them. The browser calls api-edge's auth routes. The session it gets back is posted to /auth/lumen/session (same origin only), which stores it in an HttpOnly, SameSite=Lax cookie on the CMS host. Page scripts never see it again.
  • lumen auth strategy (apps/cms/src/lib/lumen/). It resolves the cookie with GET /v1/auth/session over a new LUMEN_API service binding to api-edge, caching each answer 30 s per token hash (failures are not cached). It then finds, links (by email) or creates the users row by lumenUserId. The token is never put on req.user.
  • Roles stay Payload's. A new row has no role, so it is pending: the person sees "Waiting for access" (Payload's unauthorized view, replaced) until an admin grants editor or admin. The first admin still needs the owner's CMS_SETUP_TOKEN: /setup?token=… now sends the owner to the sign-in, and whoever signs in with that cookie while no admin exists becomes admin.
  • Sign-out (Payload's logout) revokes the Lumen session and clears the cookie.
  • CSRF. A request whose Origin names another host gets no user. No other page can write through Payload's API with the cookie, including sibling Workers on the same workers.dev site, which SameSite does not separate. This replaces Payload's csrf allowlist, which only guards Payload's own cookie (off now). It is recorded as a departure in the epic's status file.
  • Schema. Migration 206_cms_lumen_identity: role loses its default and NOT NULL, and users gains lumen_user_id with a unique index. It is converted from Payload's migration. The converter now treats ALTER COLUMN … DROP DEFAULT / DROP NOT NULL / SET … as idempotent; 200 and 205 still convert byte for byte.
  • Other components:
    • api-edge CORS gains each environment's CMS origin (only its own).
    • identity-worker's OAUTH_ALLOWED_CONSOLE_ORIGINS gains the CMS for the OAuth return.
    • cms now dependsOn api-edge.
  • Docs: CMS runbook (sign-in, opening the first admin, verify, local run), architecture, overview, ai/context/operations.md, cms-tests docs, epic status.

Verification

  • tests/cms 107 tests (new: users, lumen-strategy, lumen-accounts, lumen-session, lumen-cookies), typecheck and lint clean.
  • tests/db 597, including the 206 suite.
  • tests/identity-worker 180, including the new oauth-allowlist.
  • tests/api-edge CORS 42.
  • Schema gate: migrations 200+205+206 applied to an empty database vs Payload's push. Identical apart from where lumen_user_id sits in the column order.
  • End to end, locally, 32/32: the built Worker in workerd, a database built only from the migrations, and stage's real api-edge for sign-in. It covered:
    • a newcomer lands on the pending page;
    • the cookie is HttpOnly/Lax and the token is not in /api/users/me;
    • sign-out revokes the token at Lumen (401);
    • setup makes the first admin;
    • the admin promotes the newcomer to editor;
    • an editor cannot make themself admin;
    • the OAuth return path works;
    • the session route refuses other origins and off-admin redirects;
    • a sibling Worker's origin cannot write with the admin cookie;
    • login and first-register answer 403.

After merge I'll check stage against the task's done-when (pending page, setup → admin, second account pending until promoted, sign-out revokes) and that prod's /admin shows the sign-in (read-only).

Orun-Task: PX-2


Generated by Claude Code

The admin no longer has passwords of its own. /admin shows a Lumen sign-in
(emailed code, GitHub, Google); the session goes into an HttpOnly cookie on
the CMS host, and a `lumen` auth strategy resolves it through api-edge over
the LUMEN_API service binding and maps the Lumen user to a `users` row.

- users: local strategy off (its columns stay), `lumenUserId` (unique, set
  by no request), `role` optional with no default: no role means pending
- the first admin still needs the owner's setup token; admins grant the rest
- the pending page replaces Payload's unauthorized view; sign-out revokes
  the Lumen session
- a request naming another origin gets no user, so no other page (a sibling
  Worker on the same workers.dev site included) can write with the cookie
- migration 206_cms_lumen_identity, converted from Payload's; the converter
  now accepts column default and nullability changes as idempotent
- api-edge CORS and identity-worker's OAuth return allowlist gain the CMS
  origin of each environment
- docs: runbook, architecture, overview, operations guide; epic status

Orun-Task: PX-2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013JuHbkZCjDrGgHdzCrCRqG
@ruehowl
ruehowl marked this pull request as ready for review October 28, 2026 12:51
@ruehowl
ruehowl merged commit 4c5f0d8 into main Oct 28, 2026
19 checks passed
ruehowl added a commit to sourceplane/multi-tenant-saas-2 that referenced this pull request Oct 28, 2026
Staff accounts (admin, editor, instructor) no longer have Payload passwords.
/admin shows a Lumen sign-in (emailed code, GitHub, Google); the session
goes into an HttpOnly cookie on the CMS host, and a `lumen` auth strategy on
`users` resolves it through api-edge over the LUMEN_API service binding and
maps the Lumen user to a `users` row. Learners are a separate collection and
keep their own accounts and the academy's /login and /register. Ported from
sourceplane/lumen-payload#22 (PX1) with the LMS's differences
(multi-tenant-saas-2-console design §2-§6).

- users: local strategy off (its columns stay), `lumenUserId` (unique, set
  by no request), `role` optional with no default: no role means pending;
  the instructor role and its academies stay, and admin access still admits
  all three staff roles
- the first admin still needs the owner's setup token; admins grant the
  rest, and inviting by email links the row on that person's first sign-in
- the pending page replaces Payload's unauthorized view; sign-out revokes
  the Lumen session
- a request naming another origin gets no staff user, so no other page (a
  sibling Worker on the same workers.dev site included) can write with the
  cookie
- migration 320_cms_lumen_identity, converted from Payload's; the converter
  accepts column default and nullability changes as idempotent
- the Lumen routes live in a (site) group with its own minimal layout; the
  academy keeps /
- api-edge CORS and identity-worker's OAuth return allowlist gain the CMS
  origin of each environment
- docs: runbook, architecture, overview, operations guide; epic status

Orun-Task: LX-2


Claude-Session: https://claude.ai/code/session_013JuHbkZCjDrGgHdzCrCRqG

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants