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 API provides functions for managing user authentication, session restoration, and profile management in RuedaPro UNIPAZ. All authentication is handled through Supabase Auth.Global Variables
Stores the currently authenticated Supabase user object. Contains user ID, email, and metadata.
Stores the current user’s profile information.Properties:
id(string): User’s UUIDnombre(string): Full namerol(string): User role - ‘admin’, ‘docente’, or ‘estudiante’avatar_url(string, optional): Profile avatar URL
Functions
restoreSession()
Restores an existing Supabase authentication session on page load or app initialization. Signature:Async function with no return value
perfiles table. Updates global variables currentUser and currentProfile, then refreshes the header UI.
Behavior:
- Returns early if
supabaseClientis not initialized - Retrieves session using
supabaseClient.auth.getSession() - Extracts user metadata (nombre, rol) from JWT
- Attempts to fetch avatar from
perfilestable - Calls
updateGlobalHeader()to update UI - Logs errors to console without throwing
- updateGlobalHeader() - Updates header UI
- handleLogin() - User login
handleLogin(event, role)
Handles user login form submission with role-based authentication and routing. Signature:Form submit event object
Expected user role: ‘docente’, ‘estudiante’, or ‘admin’
Async function with no return value
- Prevents default form submission
- Validates
supabaseClientis initialized - Extracts email and password from form inputs
- Disables submit button and shows loading state
- Calls
supabaseClient.auth.signInWithPassword() - Verifies user’s actual role matches expected role
- Fetches avatar URL for docente role
- Routes to appropriate dashboard:
dashboard-docentefor docentesdashboard-estudiantefor estudiantesdashboard-adminfor admins
- Shows error if authentication fails or role mismatch
- Signs out user if role doesn’t match
- Displays user-friendly error messages in
#login-errordiv - Re-enables submit button on failure
- Prevents access if role doesn’t match
- updateGlobalHeader() - Updates header after login
- navigateTo() - Routes to dashboard
- handleLogout() - User logout
handleLogout()
Logs out the current user and clears session data. Signature:Async function with no return value
- Calls
supabaseClient.auth.signOut()if client exists - Sets
currentUser = null - Sets
currentProfile = null - Calls
updateGlobalHeader()to show login buttons - Navigates to ‘home’ route
- updateGlobalHeader() - Updates header UI
- navigateTo() - Routes to home
updateGlobalHeader()
Updates the header UI to show either authentication buttons or user menu based on login state. Signature:No return value
currentUser and currentProfile exist):
- Hides
#auth-buttonselement - Shows
#user-menuelement - Sets avatar initial to first character of user’s name
- Displays user’s full name in
#header-user-name - Displays role badge in
#header-user-rolewith appropriate styling:- Admin: red badge (
badge-danger) - Docente: blue badge (
badge-info) - Estudiante: green badge (
badge-success)
- Admin: red badge (
- Sets up panel button click handler to route to correct dashboard
- Configures avatar dropdown toggle functionality
- Adds document-level click listener to close dropdown when clicking outside
- Shows
#auth-buttonselement - Hides
#user-menuelement
#auth-buttons- Container for login buttons#user-menu- Container for user dropdown menu#header-avatar-initial- Avatar circle with user initial#header-user-name- User’s full name display#header-user-role- Role badge display#header-btn-panel- Button to navigate to dashboard#user-avatar-btn- Avatar button to toggle dropdown#user-dropdown- Dropdown menu container
- restoreSession() - Calls this after session restore
- handleLogin() - Calls this after login
- handleLogout() - Calls this after logout
Authentication Flow
Error Handling
All authentication functions handle errors gracefully:- Network errors: Display user-friendly messages
- Invalid credentials: Show authentication failed message
- Role mismatches: Explain required vs actual role
- Missing Supabase client: Fail early with alert
- Database errors: Log to console, continue operation
Security Considerations
- Passwords are never stored or logged
- Role verification prevents unauthorized dashboard access
- User metadata in JWT is trusted source for role
- Session tokens managed entirely by Supabase
- Automatic sign-out on role mismatch