Rumahjo-Android-APP/lib/data/cubits/auth/auth_state_cubit.dart

31 lines
861 B
Dart
Raw Permalink Normal View History

2024-09-07 00:58:50 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../utils/hive_utils.dart';
enum AuthenticationState { initial, authenticated, unAuthenticated, firstTime }
class AuthenticationCubit extends Cubit<AuthenticationState> {
AuthenticationCubit() : super(AuthenticationState.initial) {
_checkIfAuthenticated();
}
void _checkIfAuthenticated() {
bool userAuthenticated = HiveUtils.isUserAuthenticated();
if (userAuthenticated) {
emit(AuthenticationState.authenticated);
} else {
//When user installs app for first time then this firstTime state will be emmited.
if (HiveUtils.isUserFirstTime()) {
emit(AuthenticationState.firstTime);
} else {
emit(AuthenticationState.unAuthenticated);
}
}
}
void setUnAuthenticated() {
emit(AuthenticationState.unAuthenticated);
}
}