Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mobile/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# packages, and plugins designed to encourage good coding practices.
analyzer:
errors:
invalid_return_type_for_catch_error: ignore
use_build_context_synchronously: ignore
use_null_aware_elements: ignore
include: package:flutter_lints/flutter.yaml
Expand Down
20 changes: 18 additions & 2 deletions mobile/lib/controllers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,29 @@ class AuthState extends ChangeNotifier {
try {
final res = await _authService.getCurrentUser(_token!);
final data = res.data;

final userData = data['data'] ?? data['user'] ?? data;

_currentUser = UserModel.fromJson(userData);

await _authService.saveUserProfile(jsonEncode(userData));
notifyListeners();

} catch (e) {
debugPrint("Failed to load user profile: $e");
debugPrint("Network failed, attempting to load cached user profile: $e");

try {
final cachedData = await _authService.getCachedUserProfile();
if (cachedData != null) {
final decodedData = jsonDecode(cachedData);
_currentUser = UserModel.fromJson(decodedData);
notifyListeners();
} else {
_errorMessage = "No internet connection and no cached profile.";
notifyListeners();
}
} catch (cacheError) {
debugPrint("Cache read failed: $cacheError");
}
}
}

Expand Down
Loading
Loading