ash_authentication/test/support/example/auth_plug.ex
James Harton bab9ec363e
fix(PasswordReset): Generate the reset token using the target action, not the source action. (#25)
* fix(PasswordReset): Generate the reset token using the target action, not the source action.

Also improve tests.

* improvement(PasswordReset): rework PasswordReset to be a provider in it's own right - this means it has it's own routes, etc.
2022-11-04 11:24:33 +13:00

45 lines
915 B
Elixir

defmodule Example.AuthPlug do
@moduledoc false
use AshAuthentication.Plug, otp_app: :ash_authentication
@impl true
def handle_success(conn, nil, nil) do
conn
|> put_resp_header("content-type", "application/json")
|> send_resp(
200,
Jason.encode!(%{status: :success})
)
end
def handle_success(conn, user, token) do
conn
|> store_in_session(user)
|> put_resp_header("content-type", "application/json")
|> send_resp(
200,
Jason.encode!(%{
status: :success,
token: token,
user: %{
id: user.id,
username: user.username
}
})
)
end
@impl true
def handle_failure(conn, reason) do
conn
|> put_resp_header("content-type", "application/json")
|> send_resp(
401,
Jason.encode!(%{
status: :failure,
reason: inspect(reason)
})
)
end
end