Administration and access
The administration area is a private control surface for the site owner. It protects booking, calendar, media, and photo work behind one authentication boundary, then gives the owner a small overview and focused tools for daily operations.
Administrative application
The administrative application provides a separate operating space from the public site. Public pages do not expose the admin shell, while admin pages use the same site language and visual system without making operational data public or indexable.
The area has three main responsibilities:
- Show the state of AMA work that may need action.
- Manage media and the photos selected for public display.
- Keep the owner’s session and exit path under explicit control.
The admin surface is protected at both the page and API boundaries. This means that a private screen cannot be used to reach a private action by changing the URL or calling its endpoint directly.
Administrative surfaces
The overview is the entry point for the owner. It points to the next useful action rather than showing every tool at once.
| Surface | Purpose | Main signals |
|---|---|---|
| Overview | Summarize current work | Items needing attention, the next AMA session, new time requests, media counts, and photo counts |
| AMA | Operate the appointment service | Bookings, unresolved requests, failed background work, availability, and calendar state |
| Media | Maintain the private image catalog | Active and archived assets, transfers, processing state, review data, and retention actions |
| Photos | Curate the public photo selection | Draft and published selection state |
The child page Admin shell and access control explains the protected layout, request checks, and client response behavior in more detail.
References: app/…/page.tsx• L56-102 app/…/page.tsx• L74-176 app/…/page.tsx• L54-70 app/…/page.tsx• L49-65
Access boundaries
Access has two separate meanings. Authentication proves that a session exists. Authorization decides whether that session belongs to the site owner who may use the administrative application.
Authentication and authorization
The admin route family uses Clerk as its identity service. A signed-out visitor is sent to the Clerk sign-in flow. A signed-in user still needs the exact owner marker on the authoritative Clerk user record before the application grants access.
The owner marker is publicMetadata.siteOwner: "yes". An email address, browser state, or the data namespace used by the site does not grant administrative access. A valid session without the owner marker reaches the forbidden boundary instead of the admin application.
This flow keeps identity and business data separate. The owner identity controls access, while the stable site-owner data ID identifies the data space used by admin services.
The following diagram shows the boundary from a route request to an allowed or denied result.
flowchart TD
R[Admin page or admin API request] --> P[Authentication boundary]
P -->|No active session| S[Clerk sign-in]
P -->|Active session| O[Owner authorization check]
O -->|Marker absent or invalid| F[Forbidden response]
O -->|Owner marker valid| A[Admin page or operation]
References: proxy.ts• L26-43 proxy.ts• L61-71 lib/…/authorization.ts• L1-45 lib/…/server.ts• L15-40
Protected operations
Administrative reads and changes share the same owner boundary. Page loaders check the owner before loading private data, and admin API handlers apply the same access result before they perform an operation.
Mutation requests also sit behind request-level safeguards. Same-origin checks, actor limits, and privileged-action records reduce the chance that a valid session can be misused by an unexpected caller. The admin system does not treat a client-visible hint as proof of ownership.
An owner can therefore use the overview as a trusted starting point, but each destination remains responsible for checking access again. This defense matters when a user opens a deep link, an old page, or an API request outside the normal navigation path.
References: app/…/layout.tsx• L7-23 app/…/page.tsx• L56-78 app/…/page.tsx• L162-220 app/…/page.tsx• L54-62 lib/…/server.ts• L28-50
Session lifecycle
The session lifecycle begins at the identity provider and ends when the current session is revoked or expires. The administrative application keeps the session usable during normal work and returns the operator to authentication when the session is no longer valid.
Sign-in and session renewal
The /admin/login route is a routing entry point rather than a second login form. It sends an unauthenticated request to Clerk sign-in and sends an authorized owner to /admin.
Once the admin area is open, the Clerk client keeps the short-lived session token current in the background. This lets the static admin shell remain usable while the owner works. If an admin API call receives an authentication failure, the client performs a full navigation so the protected route can send the owner through sign-in again.
The public site can also ask whether the current session belongs to the owner. That read-only probe returns only { owner: true } or { owner: false }, so public navigation can show the Admin entry without exposing identity details or making ordinary page loads depend on Clerk.
References: app/…/page.tsx• L1-11 app/…/layout.tsx• L17-35 app/…/route.ts• L1-20 lib/…/client-response.ts• L1-18 components/preferences.tsx• L62-87
Logout handling
Sign out is available from the Preferences panel inside the admin dock. It uses a protected POST action that checks the current owner session, revokes that session at Clerk, records the successful privileged action, and redirects to the public site without caching the result.
Logout is limited to the current session. If the identity provider cannot be reached, the request fails closed rather than pretending that the session ended. Incident response must revoke all active sessions separately when an account may be exposed.
References: components/preferences.tsx• L208-215 app/…/route.ts• L9-19 lib/…/logout.ts• L28-85 docs/…/clerk-admin-operations.md• L80-100
Overview navigation
The owner navigation uses a compact dock and a linked overview. The dock gives direct access to the main tools, while the overview adds counts and the next scheduled session so the owner can start with the most important work.
Navigation dock
The admin dock exposes Overview, AMA, Media, and Photos. It also provides a return link to the public site and a Preferences panel for language, theme, sound, and sign out.
The active marker follows the current route. Subpages use a back link to return to their parent surface, so navigation stays shallow without placing every control on the overview. The public dock can reveal an Admin link only after the owner probe confirms access.
References: components/admin-dock.tsx• L20-24 components/admin-dock.tsx• L83-153 components/admin-nav.tsx• L3-61 components/preferences.tsx• L35-46 components/preferences.tsx• L193-215
Operational overview
The overview combines signals from AMA and media services into five links. Attention count includes bookings that need work and failed durable operations. The next-session row opens the booking when one exists, and the remaining rows lead to the relevant AMA, media, or photo surface.
This design makes the overview a work queue summary rather than a separate source of truth. The linked tools hold the detail and the actions. The overview only helps the owner choose where to go next.
References: app/…/AdminOverview.tsx• L69-156 app/…/page.tsx• L56-102 app/…/AdminOverview.test.tsx• L31-91
Change checklist
When these files or sections are changed, remember to consider these:
- When the owner marker or Clerk session contract changes, keep page redirects, API denial statuses, the public owner probe, and the logout path aligned.
- When an admin surface is added or renamed, update the protected route boundary, the dock, the overview row, and the parent-surface back links together.
- When an overview count changes meaning, update both its source query and the destination tool so the summary does not hide unresolved work.
- When session expiry behavior changes, preserve the full-navigation path from a 401 admin API response back to the protected sign-in boundary.
- When logout or mutation safeguards change, keep current-session revocation, same-origin checks, actor limits, and privileged-action records in the same request path.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No active Clerk session opens an admin page | The request cannot enter the admin application | Route protection sends the visitor to Clerk sign-in or fails closed |
Active user lacks publicMetadata.siteOwner: "yes" | The user receives a forbidden result | The server checks the authoritative user before returning admin data |
| Session expires during an admin API action | The client may receive an empty or non-JSON 401 response | The shared admin response handler reloads the protected route before parsing the body |
| Clerk cannot revoke the current session during logout | The operator is not told that sign out succeeded | Logout returns a service failure and does not issue the public-site redirect |
| A failed AMA operation is omitted from the overview count | The owner may miss work that needs repair | The overview adds failed unresolved operations to the attention signal |
| A private admin path is added without the Clerk route boundary | The path can bypass the main page protection | Admin page and API route families must remain covered by the request proxy |
Key files
| File | Why to read it |
|---|---|
| proxy.ts | Defines which admin page and API paths enter the authentication boundary. |
| lib/…/authorization.ts | States the distinction between an active session and an authorized site owner. |
| lib/…/server.ts | Connects owner checks to page loaders and admin request handling. |
| app/…/layout.tsx | Establishes the private admin document and identity-provider session support. |
| app/…/layout.tsx | Shows the protected layout shared by all admin pages. |
| app/…/AdminOverview.tsx | Shows how the owner’s work summary links to operational surfaces. |
| components/admin-dock.tsx | Defines the primary admin navigation and the public-site return path. |
| components/preferences.tsx | Defines the owner entry from public navigation and the admin logout control. |
| lib/…/logout.ts | Defines current-session revocation and logout failure behavior. |
| app/…/route.ts | Provides the public, minimal owner-access probe. |