mirror of
https://github.com/team-alembic/ash_authentication.git
synced 2024-09-20 21:33:10 +12:00
bab9ec363e
* 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.
45 lines
915 B
Elixir
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
|