fix(auth): correctif login et parsing user (version stable)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -43,7 +43,8 @@ class AuthService {
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is Exception) rethrow;
|
||||
throw Exception('Erreur réseau: impossible de se connecter au serveur');
|
||||
if (e is Error) throw Exception('Erreur interne: ${e.toString()}');
|
||||
throw Exception('Erreur réseau: impossible de se connecter au serveur ($e)');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,14 +57,22 @@ class AuthService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
final raw = jsonDecode(response.body);
|
||||
if (raw is! Map<String, dynamic>) {
|
||||
throw Exception('Profil invalide: réponse serveur inattendue');
|
||||
}
|
||||
// Accepter réponse directe ou wrapper { data: {...} }
|
||||
final data = raw.containsKey('data') && raw['data'] is Map<String, dynamic>
|
||||
? raw['data'] as Map<String, dynamic>
|
||||
: raw;
|
||||
return AppUser.fromJson(data);
|
||||
} else {
|
||||
throw Exception('Erreur lors de la récupération du profil');
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is Exception) rethrow;
|
||||
throw Exception('Erreur réseau: impossible de récupérer le profil');
|
||||
if (e is Error) throw Exception('Erreur interne: ${e.toString()}');
|
||||
throw Exception('Erreur réseau: impossible de récupérer le profil ($e)');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +107,8 @@ class AuthService {
|
||||
await _saveCurrentUser(user);
|
||||
} catch (e) {
|
||||
if (e is Exception) rethrow;
|
||||
throw Exception('Erreur réseau: impossible de changer le mot de passe');
|
||||
if (e is Error) throw Exception('Erreur interne: ${e.toString()}');
|
||||
throw Exception('Erreur réseau: impossible de changer le mot de passe ($e)');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user