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:
@@ -81,11 +81,11 @@ class ApiClient {
|
||||
if (requiresAuth) {
|
||||
final token = await TokenStorage.getToken();
|
||||
final username = await TokenStorage.getUsername();
|
||||
if (token == null || username == null) {
|
||||
throw Exception('Authentication required');
|
||||
if (token != null && username != null) {
|
||||
finalParams['token'] = token;
|
||||
finalParams['username'] = username;
|
||||
}
|
||||
finalParams['token'] = token;
|
||||
finalParams['username'] = username;
|
||||
// Guest mode: proceed without token — let backend decide
|
||||
}
|
||||
|
||||
if (params != null) finalParams.addAll(params);
|
||||
@@ -103,7 +103,7 @@ class ApiClient {
|
||||
return _handleResponse(url, response, finalParams);
|
||||
}
|
||||
|
||||
/// Build request body and attach token + username if required
|
||||
/// Build request body and attach token + username if available
|
||||
Future<Map<String, dynamic>> _buildAuthBody(Map<String, dynamic>? body, bool requiresAuth) async {
|
||||
final Map<String, dynamic> finalBody = {};
|
||||
|
||||
@@ -111,12 +111,11 @@ class ApiClient {
|
||||
final token = await TokenStorage.getToken();
|
||||
final username = await TokenStorage.getUsername();
|
||||
|
||||
if (token == null || username == null) {
|
||||
throw Exception('Authentication required');
|
||||
if (token != null && username != null) {
|
||||
finalBody['token'] = token;
|
||||
finalBody['username'] = username;
|
||||
}
|
||||
|
||||
finalBody['token'] = token;
|
||||
finalBody['username'] = username;
|
||||
// Guest mode: proceed without token — let backend decide
|
||||
}
|
||||
|
||||
if (body != null) finalBody.addAll(body);
|
||||
|
||||
Reference in New Issue
Block a user