mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-13 12:12:20 -06:00
Initial commit
This commit is contained in:
24
lib/features/login/bloc/local_authentication_cubit.dart
Normal file
24
lib/features/login/bloc/local_authentication_cubit.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_paperless_mobile/core/model/error_message.dart';
|
||||
import 'package:flutter_paperless_mobile/di_initializer.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
|
||||
class LocalAuthenticationCubit extends Cubit<LocalAuthenticationState> {
|
||||
LocalAuthenticationCubit() : super(LocalAuthenticationState(false));
|
||||
|
||||
Future<void> authorize(String localizedMessage) async {
|
||||
final isAuthenticationSuccessful = await getIt<LocalAuthentication>()
|
||||
.authenticate(localizedReason: localizedMessage);
|
||||
if (isAuthenticationSuccessful) {
|
||||
emit(LocalAuthenticationState(true));
|
||||
} else {
|
||||
throw const ErrorMessage(ErrorCode.biometricAuthenticationFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocalAuthenticationState {
|
||||
final bool isAuthorized;
|
||||
|
||||
LocalAuthenticationState(this.isAuthorized);
|
||||
}
|
||||
Reference in New Issue
Block a user