This document explains the implementation of the guest account feature in the Unixify application.
The application now automatically logs in users as a "guest" account when they access the system without authentication. This provides a unified experience where:
- All users are technically "authenticated" but with different permission levels
- Guest users are clearly identified in the UI
- A consistent navigation experience is maintained for all users
When a user accesses the application without a valid authentication token, the system:
- Automatically creates a guest token in localStorage
- Sets up a guest user profile with username "guest"
- Displays the guest account in the navigation bar
- Applies read-only permissions to all UI elements
The guest user experience includes:
- A yellow "Guest Account (Read-Only)" indicator in the navbar
- A special yellow dashed avatar with "G" (for Guest)
- A user dropdown menu showing the guest username and role
- Disabled edit buttons throughout the interface
- A "Register Now" banner encouraging account creation
The authentication system manages three states:
- Not Authenticated: No token of any kind (redirects to login)
- Guest User: Has a guest token (read-only access)
- Authenticated User: Has a regular auth token (permissions based on role)
The guest account is implemented through:
- A
guest_token
in localStorage that identifies guest sessions - A
isGuestUser()
function that differentiates between guest and regular users - Special CSS styling for guest UI elements
- Modified permission checking to recognize and handle guest accounts
- Updated templates to display guest-specific UI elements
- Run the simplified server:
cd /home/pfrederi/code/github.com/home/unixify/feature/UNO-861-acc-man
PORT=8083 go run cmd/simplified/main.go
- Access the application at http://localhost:8083
- You'll be automatically logged in as the guest user
- To test regular authentication, use the login page with:
- Username: admin
- Password: admin
The application provides a mock login API that accepts:
- Guest login: username "guest" with any password
- Admin login: username "admin" with password "admin"
Example:
// Guest login
fetch('/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'guest', password: 'anything' })
})
The guest account approach provides several benefits:
- Unified Code Path: The code can treat all users as authenticated, simplifying logic
- Clear Visual Indicators: Users always know their current access level
- Smoother UX: No jarring transitions between authenticated and non-authenticated states
- Easy Registration Path: Clear path for users to upgrade from guest to registered user
- Permission Management: Centralized permission system that works for all user types