mirror of
https://github.com/kevin-DL/phoenix_api_template.git
synced 2026-01-12 02:55:13 +00:00
Protect endpoints
This commit is contained in:
11
lib/phoenix_api_template_web/auth/guardian_error_handler.ex
Normal file
11
lib/phoenix_api_template_web/auth/guardian_error_handler.ex
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule PhoenixApiTemplateWeb.Auth.GuardianErrorHandler do
|
||||
import Plug.Conn
|
||||
|
||||
def auth_error(conn, {type, _reason}, _opts) do
|
||||
body = Jason.encode!(%{error: to_string(type)})
|
||||
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(401, body)
|
||||
end
|
||||
end
|
||||
11
lib/phoenix_api_template_web/auth/pipeline.ex
Normal file
11
lib/phoenix_api_template_web/auth/pipeline.ex
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule PhoenixApiTemplateWeb.Auth.Pipeline do
|
||||
use Guardian.Plug.Pipeline,
|
||||
otp_app: :phoenix_api_template,
|
||||
module: PhoenixApiTemplateWeb.Auth.Guardian,
|
||||
error_handler: PhoenixApiTemplateWeb.Auth.GuardianErrorHandler
|
||||
|
||||
plug Guardian.Plug.VerifySession
|
||||
plug Guardian.Plug.VerifyHeader
|
||||
plug Guardian.Plug.EnsureAuthenticated
|
||||
plug Guardian.Plug.LoadResource
|
||||
end
|
||||
Reference in New Issue
Block a user