Overview
The Authentication API (db.auth) provides methods for user login, logout, session management, and user profile operations. All authentication data is stored in localStorage with the key cafh_user_session_v1.
Methods
login
Authenticates a user with email and password credentials.User’s email address
User’s password
Returns a User object if authentication succeeds, or null if credentials are invalid
- Example
- Valid Credentials (Demo)
logout
Clears the current user session.- Example
- Usage in Component
getCurrentUser
Retrieves the currently authenticated user from session storage.Returns the current User object if a session exists, or null if no user is logged in
- Example
- Protected Route Guard
getAllUsers
Retrieves all users in the system (demo data).Returns an array of all User objects in the system
updateCurrentUser
Updates the current user’s profile information.Object containing the user fields to update
Returns the updated User object, or null if no session exists
- Example
- Update Avatar
User Roles
The system supports the following user roles via theUserRole enum:
SUPER_ADMIN- Full system accessADMIN- Administrative accessEDITOR- Content editing accessMEMBER- Standard member accessGUEST- Limited guest access
Storage Key
- Key:
cafh_user_session_v1 - Location:
localStorage - Format: JSON-serialized User object
Related Types
See Data Types for the completeUser interface definition.