analytics/lib/plausible_web/plugs/require_logged_out.ex

20 lines
374 B
Elixir
Raw Normal View History

2019-09-02 14:29:19 +03:00
defmodule PlausibleWeb.RequireLoggedOutPlug do
import Plug.Conn
2019-09-02 14:29:19 +03:00
def init(options) do
options
end
def call(conn, _opts) do
cond do
conn.assigns[:current_user] ->
conn
2020-03-31 16:08:00 +03:00
|> put_resp_cookie("logged_in", "true", http_only: false)
2019-09-02 14:29:19 +03:00
|> Phoenix.Controller.redirect(to: "/")
|> halt
2019-09-02 14:29:19 +03:00
:else ->
conn
end
end
end