directus-main — data model

Every store shape here is designed to make an invalid state unrepresentable.

The real Directus useAppStore tracks hydration as three separate, independently-mutated refs. Nothing stops all three from being set at once into a state that's actually meaningless — hydrated and errored, simultaneously. Every shape below was designed so that specific class of bug can't compile, not just won't happen in practice. See System Architecture for which workspace owns each shape.

Store State Shapes

Store Shape Worth knowing
useAuthStore session: Session | null — { accessToken, expiresAt } loggedIn checks expiresAt > Date.now(), not just whether a session exists — an expired session used to still report logged in
useAppStore hydrationStatus: HydrationStatus — a union of { status: 'idle' | 'hydrating' | 'hydrated' } and { status: 'error', error } One ref, one source of truth — hydrated/hydrating are derived computeds
useUserStore CurrentUser — id, email, optional first/last name fullName/initials share one getNameParts() helper instead of each re-filtering the same fields
useServerStore ServerInfo — project name, authProviders: AuthProvider[] ssoProviders compares against LOCAL_AUTH_DRIVER from packages/constants, not a hardcoded 'local' string

Error Hierarchy

abstract class DirectusError extends Error
↓ code, status, extensions — each subclass owns all three
ForbiddenError · 403 optional reason extension, falls back to a default message on empty string
InvalidCredentialsError · 401 deliberately no reason — naming which field was wrong would let an attacker enumerate valid accounts
!

Two independent-refs-that-must-stay-in-sync bugs, prevented by design: useAuthStore's accessToken/expiresAt and useAppStore's hydrated/hydrating/error both started as separate, independently-mutated refs in early drafts — the same shape of risk the real source's useAppStore still has today. Both were collapsed into one discriminated value before shipping, once the pattern in the first fix made the second one worth checking for deliberately, not by coincidence.