Overview
The Biométrico application manages authentication state through a combination of Vuex store and localStorage, providing both runtime state management and session persistence across browser refreshes.Authentication Flow
1. Login Process
When a user logs in, the application validates credentials and stores the authentication data:src/assets/js/function/login_function.js:21-35
2. Session Persistence
All authentication data is stored in localStorage to persist across browser sessions:JWT authentication token
Token type (“Bearer”)
User role (sotics, atics, or sa)
User’s email address
User’s full name
User’s ID
3. State Initialization
On application load, the Vuex store initializes from localStorage:src/store/index.js:4-11
User Roles
The system supports three user roles:SOTICS (Servicios de Organización de Tecnologías de Información y Comunicaciones) staff member
ATICS (Área de Tecnologías de Información y Comunicaciones) staff member
System administrator with full access
Checking Authentication Status
Using the isAuthenticated Getter
The most common way to check if a user is logged in:src/store/index.js:14
Getting User Information
Automatic Token Attachment
The Axios interceptor automatically attaches the authentication token to all API requests:src/assets/js/services/axios.js:8-23
Session Expiration Handling
When the server returns a 401 Unauthorized response, the application automatically:- Logs the session expiration
- Clears the authentication tokens from localStorage
- Redirects to the login page
src/assets/js/services/axios.js:36-41
Logout Process
To properly log out a user and clear all session data:logout_bio mutation clears:
- All Vuex store state
- All localStorage keys (Rol_bio, email_bio, id_bio, name_bio, token_bio, token_type_bio, user_bio)
src/store/index.js:42-58
Security Considerations
Token Storage
- Tokens are stored in localStorage for persistence
- While localStorage is vulnerable to XSS attacks, it’s commonly used for SPAs
- The 90-second request timeout helps limit exposure
Token Transmission
- Tokens are sent in the Authorization header using Bearer scheme
- All API communication should use HTTPS in production
Role Validation
- Login only succeeds for valid roles: sotics, atics, or sa
- Invalid roles are rejected during authentication
src/assets/js/function/login_function.js:21
Best Practices
- Always use getters: Use
isAuthenticatedgetter instead of directly checkingstate.token - Centralized logout: Always use the
logout_biomutation to ensure complete cleanup - Let interceptors handle tokens: Don’t manually add Authorization headers; the Axios interceptor handles this
- Handle 401 errors gracefully: The response interceptor automatically handles session expiration