Promote dev → uat: SSO bridge endpoint + role scope (GRO-1866) #96
Reference in New Issue
Block a user
Delete Branch "promote/dev-to-uat-gro-1866"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Promote dev → uat for GRO-1866 (SSO bridge endpoint + role scope).
Conflict resolution:
.gitea/workflows/ci.yml: kept uat version (branches: [main, dev, uat])src/middleware/rbac.ts: kept dev version (email null-guard, type assertion, single null-check on newStaff)See: GRO-1866
With noUncheckedIndexedAccess:true, split("@")[0] returns string|undefined, making `name` typed as string|undefined and failing the notNull staff.name insert constraint. Fix by using ?? fallback on the array access. Also add newStaff null guard after .returning() destructure — array destructuring yields T|undefined with noUncheckedIndexedAccess enabled.- Replace .select({ count: appointments.id }).limit(1) + .length with sql<number>`count(*)::int` pattern per project standard (references invoices.ts:86) - Add gte(appointments.startTime, new Date()) to upcomingAppointment query so past appointments in scheduled/confirmed status are excluded - Add visitCount regression tests: 2+ completed appointments → visitCount >= 2, no completed → visitCount = 0 Updated UAT_PLAYBOOK.md §profile-summary (visitCount regression + date filter) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>Adds POST /api/portal/session-from-auth which bridges a valid Better Auth customer session (from SSO login) to a portal impersonation session, so real SSO customers can access the client portal. The endpoint is registered before the validatePortalSession catch-all so it is not subject to that middleware. It validates the Better Auth session from request cookies, looks up the client by email, creates an active impersonation session, and returns { sessionId, clientId, clientName }. Also adds "role" to the genericOAuth scopes so Authentik propagates the role claim into Better Auth user objects (GRO-1862 root cause fix). Co-Authored-By: Paperclip <noreply@paperclip.ing>CI passes (Lint, Typecheck, Tests, Docker Build). Conflict resolution verified against spec: uat version of ci.yml kept, dev version of rbac.ts kept (null-guard, type assertion, returning()! cast). UAT_PLAYBOOK.md updated. PR is mergeable. Approved.
CTO review: APPROVED. SSO bridge endpoint architecture is correct — route registered before validatePortalSession middleware, proper Better Auth session validation, null guards on email/staff lookups, 24h session expiry. Conflict resolution verified: uat ci.yml kept, dev rbac.ts applied. CI green. Proceeding with merge to uat.