feat: Implement home screen with navigation and update login flow

This commit is contained in:
2025-08-20 23:08:08 +02:00
parent 592e79a375
commit 7792023b22
7 changed files with 71 additions and 19 deletions

View File

@@ -30,13 +30,24 @@ class AuthService extends ChangeNotifier {
Future<void> loadProfile() async {
if (token == null) return;
final res = await http.get(
Uri.parse('https://menuapi.devbeni.lol/api/me'),
headers: {'Authorization': 'Bearer $token'},
);
if (res.statusCode == 200) {
profile = jsonDecode(res.body)['data'];
notifyListeners();
try {
final res = await http.get(
Uri.parse('https://menuapi.devbeni.lol/api/me'),
headers: {'Authorization': 'Bearer $token'},
);
if (res.statusCode == 200) {
final body = jsonDecode(res.body);
// Try common shapes: { data: {...} } or { user: {...} } or the whole body
if (body is Map && body['data'] is Map) profile = Map<String, dynamic>.from(body['data']);
else if (body is Map && body['user'] is Map) profile = Map<String, dynamic>.from(body['user']);
else if (body is Map && body['FullName'] != null) profile = Map<String, dynamic>.from(body);
else profile = {'raw': body};
notifyListeners();
} else {
if (kDebugMode) print('[AuthService] loadProfile failed ${res.statusCode}: ${res.body}');
}
} catch (e) {
if (kDebugMode) print('[AuthService] loadProfile error: $e');
}
}