1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/lib/chess/auth/error_handler.ex
2023-02-04 21:35:56 -06:00

23 lines
449 B
Elixir

defmodule Chess.Auth.ErrorHandler do
@moduledoc false
use ChessWeb, :controller
import Plug.Conn
def auth_error(conn, {_type, _reason}, _opts) do
case get_format(conn) do
"html" ->
conn
|> put_flash(:info, "You must be logged in")
|> redirect(to: "/")
|> halt()
"json" ->
conn
|> put_status(403)
|> json(%{status: 403, message: "Not authorized"})
end
end
end