Authentication Entities
The authentication module contains core domain entities that represent the business objects used throughout the authentication flow.
User
The User entity represents an authenticated user in the Softbee application.
Location: lib/feature/auth/core/entities/user.dart:1
Properties
Unique identifier for the user
User’s username for display and login purposes
Indicates whether the user’s email has been verified
Indicates whether the user account is active
Constructor
const User({
required String id,
required String email,
required String username,
required bool isVerified,
required bool isActive,
});
Methods
json
Map<String, dynamic>
required
JSON object containing user data
Factory constructor that creates a User instance from a JSON object.factory User.fromJson(Map<String, dynamic> json) {
return User(
id: json['id'] ?? '',
email: json['email'] ?? '',
username: json['username'] ?? '',
isVerified: json['is_verified'] ?? false,
isActive: json['is_active'] ?? false,
);
}
Email verification status
Converts the User instance to a JSON object.Map<String, dynamic> toJson() {
return {
'id': id,
'email': email,
'username': username,
'is_verified': isVerified,
'is_active': isActive,
};
}
Usage Example
// Creating a user from JSON response
final json = {
'id': '123',
'email': '[email protected]',
'username': 'beekeeper',
'is_verified': true,
'is_active': true,
};
final user = User.fromJson(json);
// Accessing user properties
print(user.email); // Output: [email protected]
print(user.isVerified); // Output: true
// Converting user to JSON
final userJson = user.toJson();
Notes
- The
User entity is immutable (uses final fields and const constructor)
- JSON deserialization provides default values for all fields to prevent null values
- The JSON field
is_verified maps to the Dart property isVerified (snake_case to camelCase)
- The JSON field
is_active maps to the Dart property isActive