Enforce authorization on the server
OAuth and OpenID Connect have different jobs
OAuth 2.0 defines delegated access to protected resources; OpenID Connect (OIDC) adds an interoperable identity layer. An access token is intended for its resource server; an ID token reports authentication to the intended client. Neither is automatically a permission for every booking. Use an established identity integration, with appropriate validation of issuer, audience, expiry and protocol-specific checks; a modern authorization-code flow with PKCE is a common baseline. Do not implement token issuance or validation from scratch. In this example a trusted server has already established the principal. No identity-provider account, token or network service is needed.
export function bookingDecision(principal, booking, operation) { if (!principal || typeof principal.id !== 'string' || !principal.id) return 401; if (!['read', 'cancel'].includes(operation)) return 403; if (!booking || booking.studioId !== principal.studioId) return 404; if (!['member', 'manager'].includes(principal.role)) return 403; if (booking.ownerId !== principal.id && principal.role !== 'manager') return 404; if (operation === 'cancel' && booking.status !== 'pending') return 409; return 200;}A member may access only their bookings; a manager may access bookings in the same studio. A different studio always gets 404. Unknown operations and roles are denied. A completed booking cannot be cancelled. This policy assumes trusted, validated principal and booking records including studio IDs; the server must get both from trusted sources, not request-body claims. A real cancel operation must check and update the record atomically to avoid changes between check and write.
Return only the authorized view
import {bookingDecision} from './permissions.mjs';export function readBooking(principal, booking) { const status = bookingDecision(principal, booking, 'read'); if (status !== 200) return {status, body: null}; const {id, title, status: bookingStatus} = booking; return {status, body: {id, title, status: bookingStatus}};}The returned view excludes internal notes and owner information. A missing valid authentication yields 401; forbidden operations may return 403; the fixture deliberately uses 404 for inaccessible records to reduce direct disclosure of existence. Real HTTP 401 responses require the applicable authentication challenge; cookie-session conventions and API contracts need integration review. Status codes alone cannot prevent every information leak. Server queries must also scope list results by authorization; do not download all bookings and filter in React.
Keep credentials out of React state
export const sessionCookiePolicy = Object.freeze({ httpOnly: true, secure: true, sameSite: 'lax', path: '/'});// Configuration proposal only; no cookie is issued here.A server-managed session may use an opaque, unpredictable session identifier in an HttpOnly, Secure cookie, with an appropriate SameSite setting and no Domain attribute when host-only scope is sufficient. HttpOnly limits script reads; it does not prevent scripts from initiating authenticated requests. SameSite=Lax is a proposed starting point, not universal protection or a substitute for CSRF checks. Session rotation after authentication or privilege changes, server expiry and invalidation on logout belong to the server framework. Browser localStorage is script-readable and is not a universally safe token store. Use the chosen framework or identity SDK guidance for refresh, cookie scope and cross-site login behavior. Practice: compare two same-studio accounts and a different-studio manager; explain why a manager role supplied by the UI cannot grant access.