How can I send a query to Supabase in a Custom Function?

I created a userHasPermission() custom function that I'm using all over my app for authorization purposes. Currently, the function looks like this:

bool userHasPermission(
  UserPermission requiredPermission,
  List<String> authenticatedPermissions,
) {
  if (authenticatedPermissions.length < 1) return false;
  return authenticatedPermissions.contains(requiredPermission.name);
}

Currently, to use this function, I have to first fetch a user's permissions (from Supabase) and then pass those permissions into the function as authenticatedPermissions. However, I would rather just have userHasPermission() fetch the user permissions so that I can eliminate the authenticatedPermissions argument.

How can I send a Supabase query from inside of userHasPermission()?

1
3 replies