Skip to main content
The login system authenticates users against a local JSON file and stores session data in localStorage. Different user roles receive different access levels and are redirected to appropriate pages.

Admin Credentials

The application uses a static user database located at /workspace/source/public/data/users.json.

Available Users

These are example credentials for development only. In production, implement proper authentication with hashed passwords and secure token management.

Authentication Flow

The authentication is handled by AuthContext (/workspace/source/src/context/AuthContext.jsx:31-71).

Step 1: Form Submission

When the login form is submitted:

Step 2: User Validation

The system fetches the users.json file and validates credentials:
Reference: /workspace/source/src/context/AuthContext.jsx:42-52

Step 3: Session Storage

On successful authentication:
Reference: /workspace/source/src/context/AuthContext.jsx:54-57

Step 4: Role-Based Redirect

Users are redirected based on their role:
Redirects to the admin panel at /admin
Reference: /workspace/source/src/context/AuthContext.jsx:59-65

Persistent Sessions

On application load, the system checks for existing sessions:
Reference: /workspace/source/src/context/AuthContext.jsx:14-28 This ensures users remain logged in across page refreshes.

Logout Functionality

Admins can logout from the admin panel:
Reference: /workspace/source/src/layout/Admin.jsx:28-34
The logout only removes the isAuth key from localStorage. Consider also removing the role key for complete session cleanup.

Error Handling

The authentication system handles two types of errors:
  1. Validation errors: Missing email or password
  2. Authentication errors: Invalid credentials
  3. Network errors: Failed to fetch users.json
Reference: /workspace/source/src/context/AuthContext.jsx:67-70