Files
shooting-event/phoenix/lib/shooting_event_phx_web/plugs/admin_only.ex

19 lines
392 B
Elixir
Raw Normal View History

2026-04-29 00:45:48 +04:00
defmodule ShootingEventPhxWeb.Plugs.AdminOnly do
@moduledoc false
import Plug.Conn
alias ShootingEventPhx.Auth
def init(opts), do: opts
def call(conn, _opts) do
if Auth.admin_request?(conn) do
conn
else
conn
|> put_status(:unauthorized)
|> Phoenix.Controller.json(%{"message" => "invalid or expired admin token"})
|> halt()
end
end
end