ash_authentication/test/support/example/current_user_read.ex
James Harton 8797005175
feat(Ash.PlugHelpers): Support standard actor configuration. (#16)
* improvement(docs): change all references to `actor` to `user`.

The word "actor" has special meaning in the Ash ecosystem.

* chore: format `dev` directory also.

* feat(Ash.PlugHelpers): Support standard actor configuration.

* Adds the `:set_actor` plug which will set the actor to a resource based on the subject name.
* Also includes GraphQL and JSON:API interfaces in the devserver for testing.
2022-10-31 16:43:00 +13:00

17 lines
488 B
Elixir

defmodule Example.CurrentUserRead do
@moduledoc """
There's no need to actually go to the database to get the current user, when
we know it will already be in the context.
Here we just check that the actor is the same type of resource as is being
asked for.
"""
use Ash.Resource.ManualRead
@doc false
@impl true
def read(%{resource: resource}, _, _, %{actor: actor}) when is_struct(actor, resource),
do: {:ok, [actor]}
def read(_, _, _, _), do: {:ok, []}
end