4a93bd1c44
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
1.8 KiB
Dart
68 lines
1.8 KiB
Dart
class AuthSession {
|
|
const AuthSession({
|
|
required this.accessToken,
|
|
required this.userId,
|
|
required this.tenantId,
|
|
required this.username,
|
|
required this.userDisplayName,
|
|
required this.role,
|
|
required this.status,
|
|
});
|
|
|
|
final String accessToken;
|
|
final String userId;
|
|
final String tenantId;
|
|
final String username;
|
|
final String userDisplayName;
|
|
final String role;
|
|
final String status;
|
|
|
|
bool get isAdmin => role == 'admin';
|
|
bool get isActive => status == 'active';
|
|
bool get isAuthenticated => accessToken.isNotEmpty;
|
|
|
|
AuthSession copyWith({
|
|
String? accessToken,
|
|
String? userId,
|
|
String? tenantId,
|
|
String? username,
|
|
String? userDisplayName,
|
|
String? role,
|
|
String? status,
|
|
}) {
|
|
return AuthSession(
|
|
accessToken: accessToken ?? this.accessToken,
|
|
userId: userId ?? this.userId,
|
|
tenantId: tenantId ?? this.tenantId,
|
|
username: username ?? this.username,
|
|
userDisplayName: userDisplayName ?? this.userDisplayName,
|
|
role: role ?? this.role,
|
|
status: status ?? this.status,
|
|
);
|
|
}
|
|
|
|
Map<String, String> toJson() {
|
|
return {
|
|
'accessToken': accessToken,
|
|
'userId': userId,
|
|
'tenantId': tenantId,
|
|
'username': username,
|
|
'userDisplayName': userDisplayName,
|
|
'role': role,
|
|
'status': status,
|
|
};
|
|
}
|
|
|
|
factory AuthSession.fromJson(Map<String, dynamic> json) {
|
|
return AuthSession(
|
|
accessToken: json['accessToken']?.toString() ?? '',
|
|
userId: json['userId']?.toString() ?? '',
|
|
tenantId: json['tenantId']?.toString() ?? '',
|
|
username: json['username']?.toString() ?? '',
|
|
userDisplayName: json['userDisplayName']?.toString() ?? '',
|
|
role: json['role']?.toString() ?? 'unknown',
|
|
status: json['status']?.toString() ?? 'unknown',
|
|
);
|
|
}
|
|
}
|