label
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'auth_event.dart';
|
||||
part 'auth_state.dart';
|
||||
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
final UserRepository _userRepository;
|
||||
|
||||
AuthBloc({required UserRepository userRepository})
|
||||
: _userRepository = userRepository,
|
||||
super(AuthStateInitial()) {
|
||||
on<AuthEventLoginOAuth>(_onAuthEventLoginOAuth);
|
||||
on<AuthEventVerifyOAuth>(_onAuthEventVerifyOAuth);
|
||||
}
|
||||
|
||||
void _onAuthEventLoginOAuth(
|
||||
AuthEventLoginOAuth event, Emitter<AuthState> emit) async {
|
||||
emit(AuthStateProcess());
|
||||
try {
|
||||
await _userRepository.signInWithPhoneNumber(event.phone);
|
||||
|
||||
emit(const AuthStateVerifyOAuth(false));
|
||||
} catch (e) {
|
||||
emit(const AuthStateFailure());
|
||||
}
|
||||
}
|
||||
|
||||
void _onAuthEventVerifyOAuth(
|
||||
AuthEventVerifyOAuth event, Emitter<AuthState> emit) async {
|
||||
emit(AuthStateProcess());
|
||||
try {
|
||||
final bool isVerified = await _userRepository.verifyOTP(event.code);
|
||||
|
||||
(isVerified)
|
||||
? emit(AuthStateSuccess())
|
||||
: emit(const AuthStateVerifyOAuth(true));
|
||||
} catch (e) {
|
||||
emit(const AuthStateFailure());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user