feat: add guest mode — browse events without login

New file: lib/core/auth/auth_guard.dart
  Static AuthGuard class with isGuest flag and requireLogin() helper
  that shows a login prompt bottom sheet when guests try protected actions.

login_screen.dart / desktop_login_screen.dart:
  Added "Continue as Guest" button below sign-up link.
  Sets AuthGuard.isGuest = true, then navigates to HomeScreen.

api_client.dart:
  _buildAuthBody() and GET auth check no longer throw when token is missing.
  If no token (guest), request proceeds without auth — backend decides.

home_screen.dart:
  Bottom nav guards: tapping Contribute (index 2) or Profile (index 3)
  as guest shows login prompt instead of navigating.

auth_service.dart:
  AuthGuard.setGuest(false) called on successful login AND register
  so guest flag is always cleared when user authenticates.

Guest CAN: browse home, calendar, search, filter, view event details.
Guest CANNOT: contribute, view profile, book events (prompts login).
This commit is contained in:
2026-03-20 22:40:50 +05:30
parent 0c4e62d00e
commit 1c73fb8d9d
6 changed files with 130 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart' show kDebugMode, debugPrint;
import 'package:shared_preferences/shared_preferences.dart';
import '../../../core/api/api_client.dart';
import '../../../core/api/api_endpoints.dart';
import '../../../core/auth/auth_guard.dart';
import '../../../core/storage/token_storage.dart';
import '../models/user_model.dart';
@@ -33,6 +34,9 @@ class AuthService {
// candidate display name (server username or email fallback)
final displayCandidate = serverUsername ?? savedEmail;
// clear guest mode on successful login
AuthGuard.setGuest(false);
// save token (TokenStorage stays responsible for token)
await TokenStorage.saveToken(token.toString(), savedEmail);
@@ -90,6 +94,9 @@ class AuthService {
final savedRole = (res['role'] ?? 'user').toString();
final savedPhone = (res['phone_number'] ?? phoneNumber)?.toString();
// clear guest mode on successful registration
AuthGuard.setGuest(false);
// Save token + canonical user id for token storage
await TokenStorage.saveToken(token.toString(), savedEmail);