Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

428 B
Raw Blame
defmodule PlausibleWeb.RequireLoggedOutPlug do
  @moduledoc """
  Plug forcibly logging user out if they are authenticated.
  """

  import Plug.Conn

  def init(opts \\ []) do
    opts
  end

  def call(conn, _opts) do
    if conn.assigns[:current_user] do
      conn
      |> PlausibleWeb.UserAuth.set_logged_in_cookie()
      |> Phoenix.Controller.redirect(to: "/sites")
      |> halt()
    else
      conn
    end
  end
end