secureAction method
Future<void>
secureAction({
- required VoidCallback onSuccess,
- void onFailure(
- Object exception
- String? reason,
- GuardoConfig? config,
- GuardoService? guardoService,
Protects an action with biometric authentication
This method will prompt the user for biometric authentication and execute the appropriate callback based on the result.
Example usage:
context.secureAction(
onSuccess: () {
// Perform protected action
_deleteAccount();
},
onFailure: (exception) {
// Handle authentication failure
_showErrorMessage('Authentication failed: $exception');
},
reason: 'Please authenticate to delete your account',
);
Implementation
Future<void> secureAction({
required VoidCallback onSuccess,
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) {
onSuccess();
} else {
onFailure?.call(
const AuthenticationFailedException(
'Authentication was cancelled or failed',
),
);
}
} catch (e) {
onFailure?.call(e);
}
}