Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 18, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/1e865aae9f4ae0a3926ccb0e9e2af692 to your computer and use it in GitHub Desktop.
Save shankardevy/1e865aae9f4ae0a3926ccb0e9e2af692 to your computer and use it in GitHub Desktop.
defmodule MangoWeb.Plugs.AuthenticateCustomer do
import Plug.Conn
import Phoenix.Controller, only: [redirect: 2, put_flash: 3]
def init(_opts), do: nil
def call(conn, _opts) do
case conn.assigns[:current_customer] do
nil ->
conn
|> put_flash(:info, "You must be signed in")
|> redirect(to: "/login")
|> halt
_ ->
conn
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment