api specs
This commit is contained in:
18
phoenix/lib/shooting_event_phx_web/plugs/admin_only.ex
Normal file
18
phoenix/lib/shooting_event_phx_web/plugs/admin_only.ex
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
Reference in New Issue
Block a user