-
-
Save shankardevy/1e865aae9f4ae0a3926ccb0e9e2af692 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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