Skip to main content

Overview

Tienda ETCA implements a role-based authentication system that distinguishes between two user types:
  • Admin: Full access to product management and administrative features
  • Cliente: Standard client access to browse and purchase products
The authentication system uses React Context API for state management and localStorage for session persistence.

User Roles

The system supports two distinct roles:

AuthContext Implementation

The authentication logic is centralized in AuthContext.jsx located at ~/workspace/source/src/context/AuthContext.jsx:1.

State Management

Session Persistence

The system checks for existing sessions on mount:
Authentication state persists across page refreshes using localStorage.

Login Flow

The authentication flow is handled in ~/workspace/source/src/context/AuthContext.jsx:31-71:

1. Form Validation

2. User Authentication

The current implementation stores credentials in a JSON file. In production, this should be replaced with a secure backend API with proper password hashing.

Login Component

The Login UI component is located at ~/workspace/source/src/layout/Login.jsx:1:

Using the Auth Hook

Access authentication state anywhere in your app:

Context Provider

The AuthContext provides the following values:
Wrap your app with AuthProvider to enable authentication throughout the component tree.

Security Considerations

Current Implementation Limitations:
  • User credentials are stored in a static JSON file
  • Passwords are stored in plain text
  • No token-based authentication
  • No password encryption or hashing
Production Recommendations:
  • Implement secure backend authentication API
  • Use JWT tokens for session management
  • Hash passwords with bcrypt or similar
  • Add HTTPS for secure transmission
  • Implement rate limiting and account lockout