Files
syncrow-app/lib/features/auth/model/user_model.dart
2024-03-10 10:20:06 +03:00

74 lines
1.7 KiB
Dart

import 'package:syncrow_app/features/auth/model/token.dart';
class UserModel {
final String? id;
final String? email;
final String? name;
final String? photoUrl;
final String? phoneNumber;
final bool? isEmailVerified;
final bool? isAgreementAccepted;
//token decoded with jwt
//{
// "email": "Test@Test.com",
// "userId": 2,
// "uuid": "e145438c-4c62-4535-a0f4-f77958f9f9f4",
// "sessionId": "0409a7a1-6ef5-42c5-b3a1-1f15c639b301",
// "iat": 1709711675,
// "exp": 1709711975
// }
UserModel({
required this.id,
required this.email,
required this.name,
required this.photoUrl,
required this.phoneNumber,
required this.isEmailVerified,
required this.isAgreementAccepted,
});
factory UserModel.fromJson(Map<String, dynamic> json) {
return UserModel(
id: json['id'],
email: json['email'],
name: json['name'],
photoUrl: json['photoUrl'],
phoneNumber: json['phoneNumber'],
isEmailVerified: json['isEmailVerified'],
isAgreementAccepted: json['isAgreementAccepted'],
);
}
//from token
factory UserModel.fromToken(Token token) {
Map<String, dynamic> tempJson = token.decodeToken();
return UserModel(
id: tempJson['userId'].toString(),
email: tempJson['email'],
name: null,
photoUrl: null,
phoneNumber: null,
isEmailVerified: null,
isAgreementAccepted: null,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'email': email,
'name': name,
'photoUrl': photoUrl,
'phoneNumber': phoneNumber,
'isEmailVerified': isEmailVerified,
'isAgreementAccepted': isAgreementAccepted,
};
}
}