fix(GRO-2234): transparent re-mint on 401 for portal Book New submit #55
Reference in New Issue
Block a user
Delete Branch "flea-flicker/gro-2234-portal-waitlist-remint-on-401"
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?
GRO-2234 — Portal Book New: transparent re-mint on waitlist 401
Problem
A deliberately-paced Book New wizard (~1–2 min) could outlive the portal impersonation session, so the final
POST /api/portal/waitlistreturned401 {"error":"Unauthorized"}and the UI showed "Failed to book appointment. Please try again." A freshly-minted session with the same payload returned 201.Fix — one-shot re-mint + retry (defense-in-depth)
src/portal/sections/Appointments.tsxremintPortalSession()— POSTs/api/portal/session-from-auth(credentials: include) and returns a freshsessionId, ornullwhen there is no Better Auth session (staff/dev impersonation paths).handleConfirmBooking()— submits the waitlist viasubmitWaitlist(id); on a401, re-mints once (the customer's Better Auth cookie is still valid) and retries the submit with the freshX-Impersonation-Session-Id. Falls through to the existing error UI if re-mint fails.Companion API change
Pairs with groombook/api PR #183 (GRO-2234) which adds bounded sliding expiration so SSO portal sessions rarely lapse during active use. This web change is the deterministic user-facing recovery if a session does lapse.
Tests
src/__tests__/Appointments.test.tsx— new case: first waitlist POST →401, thensession-from-auth→ fresh id, then retried waitlist POST → success. Asserts exactly one re-mint and the header sequence["stale-session-id", "fresh-session-id"], and that no error is surfaced. Full suite green (66 tests); typecheck + lint clean.UAT_PLAYBOOK
Updated §5.12e — added TC-WEB-5.12.25 (slow-wizard submit succeeds; documents the re-mint+retry network sequence).
cc @cpfarhood