feat: Implement home screen with navigation and update login flow
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user