Documentation Index
Fetch the complete documentation index at: https://mintlify.com/joaoelian204/Portal-Ciudadano-Manta-web/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheuseAuthStore manages authentication state, user sessions, and profile data. It integrates with Supabase Auth and handles both citizen (ciudadano) and administrator (administrador) user types.
State Properties
Current authenticated Supabase user object
Extended user profile data from the database
Loading state for async operations
Error message from last failed operation
Flag to prevent concurrent user fetches
Getters
Returns true if a user is currently logged in
Returns true if current user has ‘ciudadano’ role
Returns true if current user has ‘administrador’ role
Actions
initAuth
Initializes authentication state and sets up auth state change listeners.Resolves when initialization is complete
- Retrieves current session
- Fetches user profile data
- Listens for auth state changes (SIGNED_IN, SIGNED_OUT, TOKEN_REFRESHED, USER_UPDATED)
- Handles automatic token refresh
- Prevents duplicate user fetches
register
Registers a new user account.User’s email address
User’s password
User profile information
Result object indicating success or failure
- Creates account in Supabase Auth
- Creates corresponding record in
usuariosoradministradorestable based on type - Sends verification email with redirect to
/login?verified=true
login
Authenticates a user with email and password.User’s email address
User’s password
Maintained for compatibility (Supabase handles persistence automatically)
Result object indicating success or failure
- Authenticates with Supabase
- Fetches user profile from
usuariosoradministradorestable - Updates store state with user data
logout
Signs out the current user.Always returns success: true after clearing local state
- Clears local state immediately
- Signs out from Supabase with 5-second timeout
- Returns success even if timeout occurs (local state is cleared)
resetPassword
Sends password reset email to user.Email address to send reset link to
Result object indicating success or failure
- Sends reset email via Supabase Auth
- Redirects to
/reset-passwordwhen user clicks link
updateProfile
Updates the current user’s profile information.Object with profile fields to update
Result object indicating success or failure
- Updates record in
usuariostable - Refetches user data after successful update
fetchUsuario (Internal)
Fetches user profile data from database. Used internally by other actions.Supabase user ID
User profile data or null if not found
- Prevents concurrent fetches with
fetchingUserflag - 10-second timeout protection
- Falls back to
administradorestable if not found inusuarios - Returns null if user doesn’t exist in either table
Usage Examples
- Citizen Registration
- Login & Check Role
- Initialize Auth
- Update Profile
Notes
The store automatically handles token refresh and maintains session state across page reloads.
