The TarFixer application now has a complete authentication system that automatically routes users to the appropriate dashboard based on their email domain.
When a user logs in (via manual login or Google Sign-In), the system analyzes their email address to determine their role:
-
Officer Dashboard (
@officer.com,@office.com)- Example:
jeeva@officer.com,admin@office.com - Access: Officer management dashboard
- Example:
-
Worker Dashboard (
@worker.com)- Example:
ramesh@worker.com - Access: Worker task management dashboard
- Example:
-
User Dashboard (All other emails including Gmail, Yahoo, Outlook, etc.)
- Example:
jeeva@gmail.com,user@yahoo.com,anyone@example.com - Access: Regular user dashboard for reporting road damage
- Example:
User enters email → System analyzes domain → Determines user type → Redirects to appropriate dashboard
- User enters email and password
- System validates email format
- System determines user type from email domain
- User is redirected to the correct dashboard
- User clicks "Continue with Google"
- Authenticates via Google
- System extracts email from Google account
- Automatically determines user type
- Redirects to appropriate dashboard
Each dashboard is protected and will:
- Check if user is authenticated
- Verify user has correct role for that dashboard
- Redirect to login page if not authenticated
- Redirect to correct dashboard if user type doesn't match
Email: admin@officer.com
Password: (any password)
Result: → Redirected to Officer.HTML dashboard
Email: worker123@worker.com
Password: (any password)
Result: → Redirected to Worker.HTML dashboard
Email: myemail@gmail.com
Password: (any password)
Result: → Redirected to User.HTML dashboard
Google Account: anything@gmail.com
Result: → Automatically redirected to User.HTML dashboard
-
Test Officer Access:
- Email:
test@officer.comoradmin@office.com - Password:
Test@1234(or any password meeting requirements) - Expected: Officer dashboard
- Email:
-
Test Worker Access:
- Email:
ramesh@worker.com - Password:
Worker@123 - Expected: Worker dashboard
- Email:
-
Test User Access:
- Email:
yourname@gmail.comor any other domain - Password:
User@1234 - Expected: User dashboard
- Email:
- No need to manually select user type
- System intelligently determines role from email
- Users cannot access dashboards they're not authorized for
- Automatic redirection to correct dashboard
- User stays logged in until they sign out
- Session data stored securely in browser
- Each dashboard shows the logged-in user's name
- Shows email and user initials
- Traditional email/password login
- Google Sign-In integration
auth.js- Core authentication systemLogin/Choose_login.html- Login page with auth integrationDashboard/Officer.HTML- Officer dashboard with protectionDashboard/Worker.HTML- Worker dashboard with protectionDashboard/User.HTML- User dashboard with protection
tarfixer_auth_token- Authentication tokentarfixer_user_data- User profile datatarfixer_user_type- User role type
- This is a client-side authentication system for demonstration purposes
- Passwords are not actually verified (any password works)
- Real production use requires a backend server with proper authentication
🔒 For Production:
- Implement server-side authentication
- Use secure password hashing (bcrypt, argon2)
- Add JWT token validation
- Implement session management
- Add HTTPS/SSL
- Use environment variables for sensitive data
Edit auth.js and modify the AUTH_CONFIG object:
userTypes: {
officer: ['@officer.com', '@office.com', '@admin.com'], // Add more domains
worker: ['@worker.com', '@contractor.com'], // Add more domains
user: ['@user.com', '@gmail.com', '@yahoo.com'] // Add more domains
}- Add new user type to
AUTH_CONFIG.userTypes - Add dashboard route to
AUTH_CONFIG.dashboards - Create new dashboard HTML file
- Add protection using
TarFixerAuth.protectDashboard('newtype')
Solution: Check browser console for errors, ensure auth.js is loaded
Solution: Check email domain mapping in auth.js
Solution: Ensure JavaScript is enabled and auth.js is properly loaded
Solution: You need to set up Google OAuth credentials (see below)
To enable real Google Sign-In:
- Go to Google Cloud Console
- Create a new project
- Enable Google Identity Services
- Create OAuth 2.0 credentials
- Replace
YOUR_GOOGLE_CLIENT_IDinauth.jswith your actual client ID - Add your domain to authorized domains
For issues or questions:
- Check browser console for error messages
- Verify all files are in correct directories
- Ensure relative paths are correct
- Test with different email patterns
Note: This system is designed for learning and demonstration. For production use, implement proper server-side authentication with a backend API.