I have created the sample ash project which created the Accounts.Users resource. This resources is guarded by the policies section. I am trying to expose a function / action called has_users
in the resource. The implementation is straightforward.
action :has_users, :boolean do
run fn _input, _ -> Ash.exists() end
end
But this does not work due to the filter
policy. AFAIK Only current user can read their deets. I tried the below policy, but it does not seem to work. Need some help / guidance on how to handle this scenario.
bypass action :has_users do
description "Check if there are any users in the database"
authorize_if always()
end
The intention - If there are no users in the db, display a “create a new admin user” page, else display a sign-in page. This is for initial “admin” user setup.