Files
paperless-mobile/lib/features/login/bloc/local_authentication_cubit.dart
Anton Stubenbord cb797df7d2 Initial commit
2022-10-30 14:15:37 +01:00

25 lines
857 B
Dart

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);
}