authorized static method
Perform an action only if the user is authorized to do so.
Provide a perform
function to execute if the user is authorized.
Provide a when
function to check if the user is authorized.
Provide an unauthorized
function to execute if the user is not authorized.
Implementation
static authorized(Function() perform,
{required bool Function() when, Function()? unauthorized}) async {
bool canPerform = when();
if (!canPerform) {
if (unauthorized != null) {
await unauthorized();
}
return;
}
await perform();
}