Context. surface admin · domain meta · route /handoff · auth anon (public path; reads customer + admin cookies) · source apps/oshun/admin/src/app/handoff/page.tsx
Last walked. —
Purpose#
Public entry point for the privileged-handoff sign-in flow into the admin
cockpit. Authenticated consumer-shell users exchange their consumer session for
an admin session via this page; the actual elevation call is
POST /api/admin/signin, dispatched from HandoffLauncher. Operators with a
valid admin cookie are redirected to returnTo or /.
Entry points#
- Public path —
PUBLIC_PATHSinapps/oshun/admin/src/middleware.tsincludes/handoff; no admin session required to reach it - Redirect target from
/unauthorized(operator clicks "Return to handoff entry") - Redirect target after middleware miss — when
/,/inbox, etc. bounce anonymous traffic via/unauthorized?reason=missing-session&returnTo=…, the operator navigates from there to/handoff - Direct URL — operator follows runbook instructions
Layout regions#
This page does NOT render AdminShell. It renders a plain
<main role="main" className={styles.page}> containing:
- Card (
section.styles.card):- Eyebrow — "Oshun · Operations"
- Heading — h1 "Privileged handoff"
- Body — "The admin cockpit is entered through an explicit privileged handoff from the consumer shell. Authenticate with your consumer account, then request elevation for the admin surfaces your role grants."
- Reason line — when
searchParams.reasonis set, renders<p className={styles.reason}>Reason: <readableReason>...</p>(mapping:missing-session/invalid-session/signed-outhave explicit copy; other values rendered verbatim) - HandoffLauncher — receives
hasCustomerSession,returnTo,requestId
States#
The page-level branching runs BEFORE rendering:
- Has admin session already —
parseAdminSessionToken(adminToken)returns valid; redirect toreturnTo ?? '/'(never renders the card) - No admin session, no consumer session —
hasCustomerSession === false;HandoffLauncherrenders themissingSessionrole="status"block: "No consumer session cookie was detected. Sign in through the consumer shell (https://oshun.app) and then return here to request elevation." - No admin session, has consumer session —
HandoffLauncherrenders the primary action button -
returnToquery param invalid —sanitizeReturnToreturns null when value doesn't start with/, starts with//, or starts with/unauthorized//handoff -
reasonquery param recognized — body showsreadableReason(value):missing-session→ "No admin session was present — request a new handoff."invalid-session→ "Admin session expired or failed verification."signed-out→ "You signed out of the admin cockpit."- other values → rendered verbatim
- HandoffLauncher submit
idle— Button label "Request admin handoff" - HandoffLauncher submit
submitting— Button label "Requesting handoff…"; disabled - HandoffLauncher submit
error—<p role="alert">with the error message (typedbody.messagefrom response orHandoff failed (HTTP <status>).) - HandoffLauncher submit
success—<p role="status">"Handoff granted. Redirecting to<redirectTo>…"; callswindow.location.assign(redirectTo)
Interactions#
- "Request admin handoff" (button — primary action)
- Function:
submit()→fetch('/api/admin/signin', { method: 'POST', credentials: 'same-origin', headers: { 'content-type': 'application/json', 'x-request-id': requestId ?? '' }, body: JSON.stringify({ returnTo }) }) - Disabled while
status.kind === 'submitting' - On
response.ok+body.ok === true, setssuccesswithbody.redirectTo(defaults to'/') and triggerswindow.location.assign(redirectTo) - Error path uses
body.messagewhen present, else "Handoff failed (HTTP)."
- Function:
- (no consumer session) prompt — no button; static copy pointing
operators to sign in through the consumer shell at
https://oshun.app
Data & contracts#
- Reads:
cookies()fromnext/headers—OSHUN_ADMIN_SESSION_COOKIE_NAME,OSHUN_CONSUMER_SESSION_COOKIE_NAMEparseAdminSessionToken(adminToken)— returns parsed session or nullheaders().get('x-request-id')— propagates from middleware (seeshell/02-routing-layouts.md)searchParams(Promise) —returnTo,reason
- Writes:
POST /api/admin/signinwith{ returnTo }JSON body andx-request-idheader; expected response shape{ ok: true, redirectTo?: string, message?: string } - Realtime: None.
- Auth/role check: NO middleware session check —
/handoffis inPUBLIC_PATHS. The page itself uses cookie presence andparseAdminSessionTokento decide what to render
Cross-references#
- Shell:
shell/03-auth-session.md(sign-in flow lives here),shell/02-routing-layouts.md(public paths list) - Sibling meta route:
unauthorized.md(the page that bounces operators back here) - Session cookie module:
apps/oshun/admin/src/lib/session-cookie.ts - Customer cookie module:
apps/oshun/admin/src/lib/customer-session.ts - Component source:
apps/oshun/admin/src/app/handoff/HandoffLauncher.tsx
Open questions / known gaps#
- Document the upstream service backing
POST /api/admin/signin— what authentication / authorization it performs to validate the consumer session for elevation -
sanitizeReturnToblocks/unauthorizedand/handoffto prevent loops; verify whether any other paths should be blocked (e.g.,/__test/*) - No CSRF protection visible on the form submit — verify the BFF endpoint requires double-submit cookie or origin check