backoffice

Implements staff-only admin features gated behind three independent security guards.

4.6k|387|Updated Jun 28, 2024
One-click install
npx skills add https://github.com/latitude-dev/latitude-llm --skill backoffice
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: backoffice
Source: https://github.com/latitude-dev/latitude-llm/tree/main/.agents/skills/backoffice
Command: npx skills add https://github.com/latitude-dev/latitude-llm --skill backoffice

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building internal admin tooling often leads to inconsistent authorization checks that leak the existence of privileged surfaces. This Skill enforces a uniform pattern for adding staff-only /backoffice features in the Latitude codebase, where every non-admin request is indistinguishable from a random 404.

Core Features & Use Cases

  • Three-layer guard enforcement: Route loader guard (requireAdminSession), server-function guard (adminMiddleware on every createServerFn), and database guard (getAdminPostgresClient with the system organization scope that bypasses RLS).
  • Anti-fingerprinting error discipline: All guard failures throw NotFoundError instead of 401/403/redirects, so non-admins cannot enumerate or fingerprint the admin surface.
  • Impersonation support: A dedicated impersonatingMiddleware for stopImpersonating, which gates on session.impersonatedBy since the active session carries the target user's role during impersonation.
  • Use Case: When adding a cross-organisation user search feature for support staff, follow the package layout (@domain/admin feature folders, apps/web/src/domains/admin/*.functions.ts, routes under routes/backoffice/<feature>/) so the guards, adapter discipline, and test strategy are applied consistently.

Quick Start

Add a new backoffice server function for searching users across all organisations, making sure it attaches adminMiddleware and uses the admin Postgres client.

Frequently Asked Questions about backoffice

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new admin-only server function in TanStack Start?▼

Call createServerFn literally at the call site and attach adminMiddleware before inputValidator, then run the use case through withPostgres using getAdminPostgresClient. Do not wrap createServerFn in a factory, because the Vite plugin pattern-matches the literal chain and a factory breaks the build.

Why do admin guard failures return 404 instead of 401 or 403?▼

Returning NotFoundError makes every refusal indistinguishable from hitting a random missing route, so non-admin users cannot enumerate or fingerprint the backoffice surface. Redirects, 401, and 403 responses all leak that a protected path exists.

What is the difference between users.role and members.role?▼

users.role is the global platform-staff flag ("user" or "admin") that gates backoffice access and is DBA-only. members.role is per-organisation ("owner", "admin", "member") and grants zero backoffice access even when set to admin.

How does the backoffice bypass row-level security safely?▼

Admin queries run through getAdminPostgresClient, a pool on the separate LAT_ADMIN_DATABASE_URL superuser secret, with withPostgres defaulting the scope to OrganizationId("system"). That scope is the only sanctioned signal to skip the RLS set_config call, and passing an organisation id from a backoffice handler is a bug.

Why does stopImpersonating use a different middleware than other admin endpoints?▼

During impersonation the session's user.role is the target's role, usually "user", so an admin-role check would reject the exit call. impersonatingMiddleware instead gates on session.impersonatedBy being set and injects both the admin and target user ids for the audit event.