37 lines
1.4 KiB
Dart
37 lines
1.4 KiB
Dart
part of 'auth_bloc.dart';
|
|
|
|
/// High-level authentication lifecycle status emitted by [AuthBloc].
|
|
enum AuthStatus { initial, loading, authenticated, unauthenticated, registered, error, totpSetup, totpEnabled }
|
|
|
|
/// Immutable authentication state including user identity and 2FA setup payload.
|
|
class AuthState extends Equatable {
|
|
const AuthState({
|
|
this.status = AuthStatus.initial,
|
|
this.userId,
|
|
this.role,
|
|
this.errorMessage,
|
|
this.totpData,
|
|
});
|
|
|
|
const AuthState.initial() : this();
|
|
const AuthState.loading() : this(status: AuthStatus.loading);
|
|
const AuthState.authenticated({String? userId, String? role}) : this(status: AuthStatus.authenticated, userId: userId, role: role);
|
|
const AuthState.unauthenticated() : this(status: AuthStatus.unauthenticated);
|
|
const AuthState.registered() : this(status: AuthStatus.registered);
|
|
const AuthState.totpEnabled() : this(status: AuthStatus.totpEnabled);
|
|
const AuthState.error(String msg) : this(status: AuthStatus.error, errorMessage: msg);
|
|
const AuthState.totpSetup(Map<String, dynamic> data) : this(status: AuthStatus.totpSetup, totpData: data);
|
|
|
|
final AuthStatus status;
|
|
final String? userId;
|
|
final String? role;
|
|
final String? errorMessage;
|
|
final Map<String, dynamic>? totpData;
|
|
|
|
/// Whether the signed-in user has the admin role.
|
|
bool get isAdmin => role == 'admin';
|
|
|
|
@override
|
|
List<Object?> get props => [status, userId, role, errorMessage, totpData];
|
|
}
|