Skip to content

Commit

Permalink
fix: render the status after we've added the Logger metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
paulswartz committed Jan 16, 2024
1 parent b3b533d commit d0f0c86
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/api_web/lib/api_web/plugs/authenticate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule ApiWeb.Plugs.Authenticate do
|> api_key()
|> authenticate()
|> add_to_logger()
|> validate_user()
end

defp authenticate(%{assigns: %{api_key: key}} = conn) when is_binary(key) do
Expand All @@ -29,10 +30,6 @@ defmodule ApiWeb.Plugs.Authenticate do

{:error, _} ->
conn
|> put_status(:forbidden)
|> put_view(ApiWeb.ErrorView)
|> render("403.json-api", [])
|> halt()
end
end

Expand Down Expand Up @@ -91,4 +88,16 @@ defmodule ApiWeb.Plugs.Authenticate do
forwarded_ip
end
end

defp validate_user(%{assigns: %{api_user: _}} = conn) do
conn
end

defp validate_user(conn) do
conn
|> put_status(:forbidden)
|> put_view(ApiWeb.ErrorView)
|> render("403.json-api", [])
|> halt()
end
end

0 comments on commit d0f0c86

Please sign in to comment.