I made a check_admin Plug to check if user’s is_admin is equal to true. If so the user can access the page otherwise he gets a 404 error.
check_admin.ex:
defmodule Gazette.CheckAdmin do
import Phoenix.Controller
import Plug.Conn
def init(opts), do: opts
def call(conn, _opts) do
current_user = Guardian.Plug.current_resource(conn)
if current_user.is_admin do
conn
else
conn
|> put_status(:not_found)
|> render(Gazette.ErrorView, "404.html")
|> halt
end
end
end
this does not work when a non-admin user tries to get to page he is not supposed to; Hence the check_admin.ex Plug tries to redirect this user to 404.html but when it get to the error view I get the following error:
function Gazette.ErrorView.render/2 is undefined (module Gazette.ErrorView is not available)
error_view.ex:
def render("404.html", _assigns) do
"Page not found"
end
any idea ?