Skip to content

Instantly share code, notes, and snippets.

@cjbell
Last active January 6, 2016 19:04
Show Gist options
  • Save cjbell/16270772bd0c4697d958 to your computer and use it in GitHub Desktop.
Save cjbell/16270772bd0c4697d958 to your computer and use it in GitHub Desktop.
defmodule MyApp.Controllers.Helpers do
import Plug.Conn
import Phoenix.Controller
def render_blank(conn) do
conn
|> send_resp(204, "")
end
def render_error(conn, status, opts) do
conn
|> put_status(status)
|> render(MyApp.ErrorView, "#{status}.json", opts)
end
def ensure_current_user(conn, _) do
case conn.assigns.current_user do
nil -> render_error(conn, 401, message: "unauthorized")
current_user -> conn
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment