Overview
F1 PitLane Predict uses a JWT-based authentication system to secure user accounts and control access to administrative features. The system supports two user types: regular users and admin users.User registration
New users can create an account through the registration form.Registration workflow
- Navigate to the Register page
- Provide required account information:
- Username - Unique identifier for the account
- Email - Valid email address
- Password - Secure password
- Submit the registration form
- Receive confirmation upon successful registration
Usernames and email addresses must be unique. The system will reject registration attempts with duplicate credentials.
Registration form
The registration component collects user information:Registration API
Registration data is sent to the/api/user/register endpoint:
User login
Existing users authenticate through the login form.Login workflow
- Navigate to the Login page
- Enter your credentials:
- Username
- Password
- Submit the login form
- Receive a JWT token upon successful authentication
- Token is stored in localStorage for subsequent requests
The login button is disabled if you’re already authenticated. Log out first to switch accounts.
Login form
The login component handles authentication:Login API
Credentials are verified against the/api/user/login endpoint:
JWT token management
Token structure
Successful login returns a JWT token containing:- User ID - Unique user identifier
- Username - Account username
- User type - Role (“regular” or “admin”)
- Expiration - Token validity period (1 hour)
Token storage
Tokens are stored in browser localStorage:Token verification
The application checks authentication status on page load:User types and roles
- Regular users
- Admin users
Capabilities:
- View driver standings
- Browse team information
- Check race schedules
- See race results
- Access driver and team details
- Navigate through all public pages
- Cannot create, update, or delete drivers
- Cannot modify team information
- Cannot manage race calendar
- No access to admin controls
Role-based access control
Admin operations require JWT token validation:Token expiration
The system checks token expiration before processing requests:Tokens expire after 1 hour. You’ll need to log in again to refresh your authentication.
User database schema
User accounts are stored with the following structure:- Unique constraints on username and email
- Hashed passwords for security
- Default user type is “regular”
- Timestamps for account creation and last login
Password security
Passwords are hashed using bcrypt:Authentication states
Unauthenticated
- No token in localStorage
- Limited to viewing public data
- No admin controls visible
- Can register or log in
Authenticated
- Valid token in localStorage
- Full data access
- Admin controls visible (if admin role)
- Can perform role-appropriate actions
Session management
The application reloads after successful login to update the UI:- Authentication state is reflected across all components
- Admin controls appear for authorized users
- UI adapts to user permissions
Security best practices
For production deployment, ensure you:
- Use environment variables for JWT secret keys
- Implement HTTPS for all authentication endpoints
- Add rate limiting to prevent brute force attacks
- Implement password strength requirements
- Consider adding two-factor authentication
- Use secure, httpOnly cookies instead of localStorage for tokens