This document specifies the behavior of the direct login feature that allows existing users to access the lobby authentication system without invite links.
- Variable:
MULTI_DEVICE_AUTH_ENABLED - Default:
"true" - Values:
"true"(enabled) or"false"(disabled)
- ✅ When Enabled: Login options visible,
/loginroute accessible - ❌ When Disabled: Login options hidden,
/loginroute returns 404 or redirect
templates/logged_out.html- "Login as Existing User" buttontemplates/unauthorized.html- "Access Required" pagetemplates/login.html- Login form itself
{% if MULTI_DEVICE_AUTH_ENABLED %}
<!-- Show login button/form -->
{% endif %}- When Feature Enabled: Show login form or process login
- When Feature Disabled: Return 404 Not Found or redirect to logged_out
- Username exists in
Usertable MULTI_DEVICE_AUTH_ENABLED = trueREQUIRE_APPROVAL_FOR_EXISTING_USERS = true(default)
- User submits existing username
- System validates username exists ✅
- Rate limiting check (3 requests/hour per user/IP)
- Duplicate request check (no pending requests from same IP/device in last hour)
- Create authentication request using existing
create_auth_request()helper - Create half-authenticated session with
is_fully_authenticated = false - Redirect to
/auth/status(existing lobby page)
- ✅ Rate limiting via
check_rate_limit(user_id, ip_address) - ✅ Device fingerprinting via User-Agent header
- ✅ IP address logging
- ✅ Audit trail via
log_auth_action() - ✅ Duplicate request prevention
- Same as existing multi-device auth:
- Admin approval (instant)
- Self-approval (if user has another fully authenticated device)
- Peer approval (2 community members by default)
- User gains full authentication
- Session upgraded to
is_fully_authenticated = true - Automatic redirect to main feed (
/)
- Username does NOT exist in
Usertable - User submits username via
/loginform
if not existing_user:
return templates.TemplateResponse(
"login.html",
{
"request": request,
"error": "Username not found. Please check your username or request an invite link to create a new account.",
"username": username.strip()
}
)Pros:
- Clear messaging about what went wrong
- Directs users to proper registration flow
- Prevents username enumeration attacks
- Simple implementation
Cons:
- Requires users to know exact existing usernames
- No path for new user registration via login form
Pros:
- Streamlined user experience
- Single entry point for all users
Cons:
- Security risk - anyone can create accounts
- Bypasses invite-only community model
- Could enable spam/abuse
- Conflicts with existing invite-based registration
Pros:
- Configurable behavior
- Maintains security when needed
- Flexibility for different deployment scenarios
Cons:
- Additional complexity
- More configuration to manage
Rationale:
- Preserves Community Model: The application is designed as an invite-only community
- Maintains Security: Prevents unauthorized account creation
- Clear User Guidance: Error message directs users to proper registration path
- Consistent with Existing System: Aligns with current invite-based workflow
- Current: Error message reveals username doesn't exist
- Risk Level: Low (community members likely know each other)
- Mitigation Options:
- Generic error: "Invalid login credentials"
- Rate limiting on failed attempts
- Honeypot detection
- ✅ Current: Rate limiting via IP address
- ✅ Enhancement: Failed attempt tracking per username
- ✅ Security: Temporary blocks after repeated failures
- Condition:
MULTI_DEVICE_AUTH_ENABLED = false - Response: 404 Not Found or redirect
- User Message: Login options not visible
- Condition: Username doesn't exist in database
- Response: 400 Bad Request with error template
- User Message: "Username not found. Please check your username or request an invite link to create a new account."
- Condition: Exceeded 3 requests per hour per user/IP
- Response: 429 Too Many Requests with error template
- User Message: "Too many login attempts. Please try again later."
- Condition: Pending request from same IP/device within 1 hour
- Response: 400 Bad Request with error template
- User Message: "You already have a pending login request from this device. Please wait for approval."
- Condition: Empty/invalid username format
- Response: 422 Unprocessable Entity
- User Message: Form validation errors
return templates.TemplateResponse(
"login.html",
{
"request": request,
"error": "User-friendly error message",
"username": submitted_username # Preserve input
}
)| MULTI_DEVICE_AUTH_ENABLED | REQUIRE_APPROVAL_FOR_EXISTING_USERS | Login Feature Behavior |
|---|---|---|
false |
false |
❌ Login options hidden, route disabled |
false |
true |
❌ Login options hidden, route disabled |
true |
false |
|
true |
true |
✅ Login requires approval (lobby flow) |
MULTI_DEVICE_AUTH_ENABLED=true
REQUIRE_APPROVAL_FOR_EXISTING_USERS=true
PEER_APPROVAL_COUNT=2User visits /login
↓
Enters existing username
↓
System validates + creates auth request
↓
Redirected to /auth/status (lobby)
↓
Waits for approval (auto-refresh page)
↓
Gets approved by admin/self/peers
↓
Auto-redirected to main feed
User visits /login
↓
Enters non-existing username
↓
System returns error message
↓
User sees preserved username + error
↓
User can retry or request invite link
- ✅ Authentication Helper:
create_auth_request(),create_session() - ✅ Security System:
check_rate_limit(), rate limiting, audit logging - ✅ Lobby System:
/auth/status,/auth/pending, approval workflow - ✅ Session Management: Half-authenticated sessions, automatic upgrades
- Database schema
- Approval workflow logic
- Security infrastructure
- Existing authentication flows
- Admin interfaces
- Login form renders correctly when feature enabled/disabled
- Username validation (existing vs non-existing)
- Rate limiting enforcement
- Error message accuracy
- Session creation and redirection
- Complete login flow for existing users
- Error handling for non-existing users
- Feature flag toggle behavior
- Integration with existing lobby system
- Rate limiting across multiple requests
- Username enumeration protection
- Rate limiting effectiveness
- Session security validation
- CSRF protection
- Input sanitization
- Username Suggestions: "Did you mean..." for typos
- Contact Form: Allow non-existing users to request invites
- Registration Queue: Lobby for new user requests (admin approval)
- Enhanced Security: Device fingerprinting, anomaly detection
- User Feedback: Progress indicators, estimated approval times
ALLOW_NEW_USER_REQUESTS: Enable registration requests from login formREQUIRE_EMAIL_VERIFICATION: Email verification for login attemptsENABLE_USERNAME_SUGGESTIONS: Suggest similar existing usernames
- Login success rate (existing users)
- Average time to approval in lobby
- Error rate reduction vs invite-link flow
- User satisfaction with login experience
- Security incident rate
- Login attempt frequency
- Error type distribution
- Rate limiting triggers
- Approval time metrics
- Community growth via login feature