docs: Add policies to the sample User resource, so that data is protected by default

This commit is contained in:
Rebecca Le 2024-03-01 12:20:34 +08:00
parent 27f4502aba
commit 5a14db1d24
No known key found for this signature in database
GPG key ID: 45EC503B31710A41

View file

@ -169,7 +169,8 @@ generation enabled.
defmodule MyApp.Accounts.User do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication]
extensions: [AshAuthentication],
authorizers: [Ash.Policy.Authorizer]
attributes do
uuid_primary_key :id
@ -204,12 +205,17 @@ defmodule MyApp.Accounts.User do
identity :unique_email, [:email]
end
# If using policies, add the folowing bypass:
# policies do
# bypass AshAuthentication.Checks.AshAuthenticationInteraction do
# authorize_if always()
# end
# end
# You can customize this if you wish, but this is a safe default that
# only allows user data to be interacted with via AshAuthentication.
policies do
bypass AshAuthentication.Checks.AshAuthenticationInteraction do
authorize_if always()
end
policy always() do
forbid_if always()
end
end
end
```