fix(auth): correctif login et parsing user (version stable)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -32,30 +32,42 @@ class AppUser {
|
||||
});
|
||||
|
||||
factory AppUser.fromJson(Map<String, dynamic> json) {
|
||||
final id = json['id']?.toString();
|
||||
final email = json['email']?.toString();
|
||||
final role = json['role']?.toString();
|
||||
if (id == null || id.isEmpty) {
|
||||
throw Exception('Profil invalide: id manquant');
|
||||
}
|
||||
if (email == null || email.isEmpty) {
|
||||
throw Exception('Profil invalide: email manquant');
|
||||
}
|
||||
if (role == null || role.isEmpty) {
|
||||
throw Exception('Profil invalide: rôle manquant');
|
||||
}
|
||||
return AppUser(
|
||||
id: json['id'] as String,
|
||||
email: json['email'] as String,
|
||||
role: json['role'] as String,
|
||||
id: id,
|
||||
email: email,
|
||||
role: role,
|
||||
createdAt: json['cree_le'] != null
|
||||
? DateTime.parse(json['cree_le'] as String)
|
||||
? DateTime.tryParse(json['cree_le'].toString()) ?? DateTime.now()
|
||||
: (json['createdAt'] != null
|
||||
? DateTime.parse(json['createdAt'] as String)
|
||||
? DateTime.tryParse(json['createdAt'].toString()) ?? DateTime.now()
|
||||
: DateTime.now()),
|
||||
updatedAt: json['modifie_le'] != null
|
||||
? DateTime.parse(json['modifie_le'] as String)
|
||||
? DateTime.tryParse(json['modifie_le'].toString()) ?? DateTime.now()
|
||||
: (json['updatedAt'] != null
|
||||
? DateTime.parse(json['updatedAt'] as String)
|
||||
? DateTime.tryParse(json['updatedAt'].toString()) ?? DateTime.now()
|
||||
: DateTime.now()),
|
||||
changementMdpObligatoire:
|
||||
json['changement_mdp_obligatoire'] as bool? ?? false,
|
||||
nom: json['nom'] as String?,
|
||||
prenom: json['prenom'] as String?,
|
||||
statut: json['statut'] as String?,
|
||||
telephone: json['telephone'] as String?,
|
||||
photoUrl: json['photo_url'] as String?,
|
||||
adresse: json['adresse'] as String?,
|
||||
ville: json['ville'] as String?,
|
||||
codePostal: json['code_postal'] as String?,
|
||||
json['changement_mdp_obligatoire'] == true,
|
||||
nom: json['nom']?.toString(),
|
||||
prenom: json['prenom']?.toString(),
|
||||
statut: json['statut']?.toString(),
|
||||
telephone: json['telephone']?.toString(),
|
||||
photoUrl: json['photo_url']?.toString(),
|
||||
adresse: json['adresse']?.toString(),
|
||||
ville: json['ville']?.toString(),
|
||||
codePostal: json['code_postal']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user