Test denied access despite visible UI
A route guard improves navigation, not authorization
A client-side route guard chooses which view to display. The browser can be modified and previously rendered permissions may become stale. A route can also be requested directly. A server must independently check each resource and operation, including requests made by route loaders and actions. Parent-only checks are insufficient if child loaders can be requested independently.
import React from 'react';import {Navigate} from 'react-router';export default function BookingGate({session, children}) { if (session.kind === 'loading') return <p role="status">Checking access...</p>; if (session.kind === 'signed-out' || session.kind === 'expired') { return <Navigate to="/sign-in" replace />; } if (session.kind === 'signed-in') return children; if (session.kind === 'forbidden') return <p>Access denied.</p>; return <p>Unable to check access. Please retry.</p>;}This partial React Router v7 declarative fixture requires a router and a real sign-in route in the surrounding application. A fixed internal destination avoids accepting arbitrary return URLs. It intentionally does not mount protected children while loading or denied. For a signed-in session the server may still reject a particular booking. Render a denial message when that happens, and clear the stale private view. Do not redirect every 403 into a login loop.
Coordinate logout across tabs
export function connectLogoutHint(makeChannel, onInvalidate) { const channel = makeChannel('studio-session'); function receive(event) { if (event.data?.type === 'session-ended') onInvalidate(); } channel.addEventListener('message', receive); return { notify() { channel.postMessage({type:'session-ended'}); }, close() { channel.removeEventListener('message', receive); channel.close(); } };}Pass name => new BroadcastChannel(name) in an approved browser with support; call close on cleanup. After confirmed server logout, invalidate the sending tab locally and notify other tabs to clear their private views and recheck when appropriate. The sender does not receive its own message on the sending channel. The message carries no account identity or credentials. Same-origin contexts sharing the relevant storage partition may receive it; it is only a hint, not trusted evidence of identity or successful logout. Fallback: revalidate on focus and protected requests. Missing or unsupported messages must not preserve server authorization.
Test denial even if a button is visible
import {test} from 'node:test';import assert from 'node:assert/strict';import {bookingDecision} from './permissions.mjs';import {readBooking} from './booking-api.mjs';const booking = {id:'b1', studioId:'s1', ownerId:'a', title:'Pottery', status:'pending'};test('visible control is not a server permission', () => { const visibleCancelButton = true; const principal = {id:'b', studioId:'s1', role:'member'}; assert.equal(visibleCancelButton, true); assert.equal(bookingDecision(principal, booking, 'cancel'), 404); assert.deepEqual(readBooking(principal, booking), {status:404, body:null});});Run node --test denied-access.test.mjs in the fixture directory. The test deliberately sets a UI flag to true but passes a different authenticated member to the server model. The expected decision is 404 with no body. This is a pure policy test, not a real HTTP or React test. In an approved integration environment, also verify direct API calls without authentication, cross-studio and stale-role denial, revocation after logout, two-tab invalidation, focus after navigation and no private data in cache after account switch. Never use real accounts for this exercise. Practice: add a same-studio manager allow case and a different-studio manager deny case. Explain why passing these tests does not establish correct identity-provider or session integration.