Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielpose1996-stack/ruedadeproyectos/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The authentication system in RuedaPro UNIPAZ handles user login, logout, session management, and role-based access control. All authentication functions are located injs/auth.js and use Supabase Auth as the backend service.
Global State
The authentication system maintains two global variables that represent the current user state:currentUser
currentUser variable holds the Supabase authentication user object returned from supabaseClient.auth.getSession() or signInWithPassword().
Type: User | null
Properties:
id(string) - User UUIDemail(string) - User email addressuser_metadata(object) - Custom metadata includingnombreandrolcreated_at(string) - Account creation timestamp- Additional Supabase auth properties
currentProfile
currentProfile variable holds application-specific user profile information extracted from the authentication user.
Type: Profile | null
Structure:
Core Functions
handleLogin()
Authenticates a user with email and password for a specific role.The form submit event object (used to prevent default form submission)
The role being authenticated. Must be one of:
'estudiante', 'docente', or 'admin'Function Signature
Behavior
- Prevents default form submission
- Validates Supabase client is initialized
- Extracts email and password from form inputs
- Disables submit button and shows loading state
- Calls
supabaseClient.auth.signInWithPassword() - Extracts user metadata (role, nombre) from JWT
- Verifies the user’s role matches the requested role
- Sets
currentUserandcurrentProfileglobal variables - Fetches avatar URL if user is a docente
- Navigates to role-specific dashboard on success
- Shows error message if authentication fails or role mismatch
Example Usage
Success Flow
Error Handling
Authentication Error:Required DOM Elements
#login-email- Email input field#login-password- Password input field#login-error- Error message container- Submit button within the form
handleLogout()
Signs out the current user and clears authentication state.Function Signature
Behavior
- Calls
supabaseClient.auth.signOut()to end Supabase session - Clears
currentUser(sets tonull) - Clears
currentProfile(sets tonull) - Updates global header to show login buttons
- Navigates to home page
Example Usage
Implementation
restoreSession()
Restores user session from Supabase on page load or refresh.Function Signature
Behavior
- Checks if Supabase client is initialized
- Calls
supabaseClient.auth.getSession()to retrieve active session - If session exists, extracts user data
- Builds
currentProfilefromuser_metadata - Attempts to fetch avatar URL from
perfilestable - Updates global header to reflect logged-in state
Example Usage
Implementation
Error Handling
Errors during session restoration are logged but don’t prevent the application from loading:updateGlobalHeader()
Updates the application header to reflect current authentication state. Note: This function is defined injs/router.js but is closely tied to authentication state.
Function Signature
Behavior
When User is Logged In:- Hides authentication buttons (
#auth-buttons) - Shows user menu (
#user-menu) - Sets avatar initial to first character of user name
- Displays user name in header
- Displays role badge with appropriate styling
- Configures “Ir a mi Panel” button to navigate to role-specific dashboard
- Sets up dropdown toggle functionality
- Shows authentication buttons (
#auth-buttons) - Hides user menu (
#user-menu)
Example Usage
Implementation Details
Required DOM Elements
#auth-buttons- Container for login buttons#user-menu- Container for user dropdown#header-avatar-initial- Avatar initial display#header-user-name- User name display#header-user-role- Role badge display#header-btn-panel- Dashboard navigation button#user-dropdown- Dropdown menu container
Role Verification
Role Types
The system supports three role types:| Role | Description | Dashboard Route |
|---|---|---|
estudiante | Students who view their project evaluations | dashboard-estudiante |
docente | Faculty members who evaluate projects | dashboard-docente |
admin | Administrators who manage users and assignments | dashboard-admin |
Role Source
User roles are stored in the JWTuser_metadata field and set during user creation. This approach:
- Avoids database round-trips during login
- Prevents RLS policy issues during authentication
- Ensures roles are cryptographically signed by Supabase
Role Verification Pattern
Protected Routes
Routes are protected in the router by checkingcurrentProfile.rol:
Session Management
Session Lifecycle
Session Storage
Supabase automatically stores the session JWT in browser localStorage. The session includes:- Access token (JWT)
- Refresh token
- User metadata
- Expiration timestamp
Session Expiry
Sessions are automatically refreshed by the Supabase client. If a session expires:- The user is automatically logged out
currentUserandcurrentProfilebecomenull- The user must log in again
Security Considerations
Password Security
- Passwords are transmitted over HTTPS only
- Passwords are hashed by Supabase (never stored in plaintext)
- Password complexity requirements enforced by Supabase
JWT Security
- JWTs are signed by Supabase (tamper-proof)
- JWTs contain user ID and metadata
- JWTs expire after configurable period
XSS Protection
User data is sanitized before rendering:Session Fixation Prevention
- New session created on each login
- Old sessions invalidated on logout
Complete Example
Here’s a complete example of implementing authentication in a custom login view:Testing Authentication
Manual Testing
-
Test Valid Login:
- Navigate to login page for a role
- Enter valid credentials
- Verify redirect to correct dashboard
- Verify header shows user info
-
Test Invalid Login:
- Enter incorrect credentials
- Verify error message displays
- Verify user remains on login page
-
Test Role Mismatch:
- Navigate to docente login
- Enter estudiante credentials
- Verify error message about role mismatch
- Verify user is logged out
-
Test Session Persistence:
- Log in successfully
- Refresh the page
- Verify user remains logged in
- Verify correct dashboard displays
-
Test Logout:
- Click logout button
- Verify redirect to home page
- Verify header shows login buttons
- Verify cannot access protected routes
Related Documentation
API Overview
Understanding the overall system architecture
Router API
Client-side routing and navigation
Database Schema
User tables and relationships
Security Guide
Security best practices and RLS policies