ash_authentication/dev/dev_server/test_page.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

37 lines
887 B
Elixir

defmodule DevServer.TestPage do
@moduledoc """
Displays a very basic login form according to the currently configured
Überauth providers.
"""
@behaviour Plug
alias Plug.Conn
require EEx
EEx.function_from_file(:defp, :render, String.replace(__ENV__.file, ".ex", ".html.eex"), [
:assigns
])
@doc false
@impl true
@spec init(keyword) :: keyword
def init(opts), do: opts
@doc false
@spec call(Conn.t(), any) :: Conn.t()
@impl true
def call(conn, _opts) do
resources = AshAuthentication.authenticated_resources(:ash_authentication)
current_users =
conn.assigns
|> Stream.filter(fn {key, _value} ->
key
|> to_string()
|> String.starts_with?("current_")
end)
|> Map.new()
payload = render(resources: resources, current_users: current_users)
Conn.send_resp(conn, 200, payload)
end
end