Overview
Portal Ciudadano Manta implements a robust authentication system using Supabase Auth with role-based access control for citizens and administrators. The system includes email verification, password recovery, session management, and security features like rate limiting.User Types
The system supports two distinct user roles:Ciudadano
Regular citizens who can submit reports, participate in surveys, and view news
Administrador
Administrative users who manage content, review reports, and access the admin panel
Authentication Store
The authentication logic is centralized inauth.store.ts using Pinia for state management.
State Interface
User Profile Structure
Core Authentication Functions
User Registration
Registration creates both a Supabase Auth user and a profile record in the appropriate table.User Login
Login authenticates the user and fetches their complete profile.Session Management
The system automatically manages sessions and listens for auth state changes.Security Features
Rate Limiting
The login form implements progressive rate limiting to prevent brute force attacks:Track Failed Attempts
The system tracks failed login attempts using localStorage and sessionStorage.
Progressive Lockout
Each failed attempt increases the lockout duration:
- First lockout: 5 minutes
- Second lockout: 10 minutes
- Third lockout: 15 minutes, and so on
Password Recovery
Users can reset their password via email:Email Recovery
Users who forget their email can retrieve it using their Ecuadorian ID (cédula):Cedula Validation
The system validates Ecuadorian national IDs using the official algorithm:Role-Based Access Control
The system provides helper functions to check user roles:Usage in Components
Best Practices
Session Persistence
Session Persistence
Supabase automatically handles session persistence. The
rememberMe parameter is maintained for compatibility but sessions persist by default through localStorage.Error Handling
Error Handling
Always handle authentication errors gracefully and provide user-friendly messages. The system includes translations for common error scenarios.
Token Refresh
Token Refresh
Supabase automatically refreshes tokens. The auth state listener handles
TOKEN_REFRESHED events to update the UI without refetching user data.Concurrent Fetch Prevention
Concurrent Fetch Prevention
The
fetchingUser flag prevents multiple concurrent user profile fetches, improving performance and preventing race conditions.Related Resources
Supabase Auth Docs
Official Supabase authentication documentation
Vue Router Guards
Protecting routes with navigation guards
