Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DavidCevallos15/Crucidrive---APP/llms.txt
Use this file to discover all available pages before exploring further.
useAuthStore is the single source of truth for authentication state in CruciDrive. It stores the Supabase Session, the User object, and the extended UserProfile fetched from the public.perfiles table. Every screen that needs to know whether the user is logged in, or what role they hold (pasajero, conductor, admin), reads directly from this store instead of calling Supabase’s client directly.
State shape
The store’s internal state is typed asAuthState:
UserProfile type
UserProfile maps directly to a row in public.perfiles and extends the base Supabase User with CruciDrive-specific fields:
estado_operativo is only meaningful for conductor accounts and drives the driver’s availability indicator on the map. calificacion is a floating-point average updated server-side after each completed ride.
Actions
| Action | Signature | Description |
|---|---|---|
setSession | (session: Session | null) => void | Stores the Supabase session and derives user from session.user. Passing null clears both. |
setProfile | (profile: UserProfile | null) => void | Stores the extended profile row fetched from public.perfiles after login. |
setLoading | (loading: boolean) => void | Toggles the isLoading flag used during auth transitions. |
setInitialized | (initialized: boolean) => void | Marks the app-mount session check as complete. Should only be called once at startup. |
clearSession | () => void | Resets all auth state to logged-out defaults (see below). |
Reading state
Subscribe to individual slices to avoid unnecessary re-renders. Always prefer granular selectors over selecting the entire store object:clearSession
clearSession is the logout action. It atomically resets the following slice back to initial defaults in a single set call, avoiding any intermediate render with partial state:
isInitialized is not reset by clearSession — it remains true so the app does not show the splash screen again after logout.
isInitialized is false until the Supabase onAuthStateChange handler fires on app mount and the resulting session check completes. Render a splash or skeleton screen while isInitialized === false to avoid flashing the login screen for already-authenticated users.