guardoAsyncAction method
Future<void>
guardoAsyncAction({
- required Future<
void> onSuccess(), - Future<
void> onFailure(- Object exception
- String? reason,
- GuardoConfig? config,
- GuardoService? guardoService,
Protects an async action with biometric authentication
This method will prompt the user for biometric authentication and execute the appropriate async callback based on the result.
Example usage:
await context.guardoAsyncAction(
onSuccess: () async {
// Perform protected async action
await _uploadSecureData();
},
onFailure: (exception) async {
// Handle authentication failure
await _logAuthenticationFailure(exception);
},
reason: 'Please authenticate to upload data',
);
Implementation
Future<void> guardoAsyncAction({
required Future<void> Function() onSuccess,
Future<void> Function(Object exception)? onFailure,
String? reason,
GuardoConfig? config,
GuardoService? guardoService,
}) async {
try {
final authenticated = await _performAuthentication(
guardoService: guardoService,
config: config,
reason: reason,
);
if (authenticated) {
await onSuccess();
} else {
await onFailure?.call(
const AuthenticationFailedException(
'Authentication was cancelled or failed',
),
);
}
} catch (e) {
await onFailure?.call(e);
}
}