import React from 'react'; import { DoorOpen } from 'lucide-react'; import { useAuthServiceContext } from '../../services'; /** * THE SCREEN THAT ASKS BEFORE TAKING A SESSION, INSTEAD OF TAKING IT SILENTLY. * * WHAT IT REPLACES. Restoring a signed-in STAFF session on the patient mount - or a PATIENT session on * the staff mount - matched none of the identity branches in `AuthService.fetchUserData`, so the code fell * through to `logout()`. Measured on 2026-08-19 in both directions: every auth key gone, including the * REFRESH token, which is what proves it was a deliberate sign-out rather than an expiry. * * THE COST IS THE RECOVERY, NOT THE FREQUENCY. There is no password - signing in is an emailed * one-time code. So a wrong bookmark mid-shift meant: open your email, wait, paste, and find your way * back. The two portals sit side by side in bookmarks, and Spencer and Ed switch between them constantly. * * IT IS NOT ARGUED THAT HOLDING BOTH AT ONCE SHOULD BE ALLOWED. One origin means one storage prefix, * and quietly keeping two identities under it is exactly what the single-origin rule warns against. The * eviction is fine. **Doing it without asking is the defect**, which is why this is a question and not a * change to how sessions are stored. * * THE SESSION IS STILL LIVE WHILE THIS IS ON SCREEN. Nothing has been cleared; `AuthService` sets a * flag and returns. That is what makes the safe choice genuinely free - and it is the control the card * insists on, because a confirmation shown *after* the session is gone is decoration. */ export const CrossPortalGate: React.FC<{ holding: 'staff' | 'patient' }> = ({ holding }) => { const { logout } = useAuthServiceContext(); const heldLabel = holding === 'staff' ? 'staff portal' : 'patient portal'; const openedLabel = holding === 'staff' ? 'patient portal' : 'staff portal'; return (
This is the {openedLabel}, and only one of the two can be open on this device at a time. Continuing here will sign you out of the {heldLabel}.
Signing back in needs a new code emailed to you, so if you meant to stay in the {heldLabel}, go back now.