analytics/lib/plausible_web/plugs/first_launch_plug.ex
ruslandoga 0b7870dc4d
improve first launch experience for self-hosters (#2357)
* first launch

* dynamic children, wait for repo

* remove wait_for_repo and app env manipulations

* don't mention free trial in self-hosted pages

* add changelog

* assigns[:is_selfhost] -> @is_selfhost

* better changelog wording

* rm admin_user, admin_email, admin_pwd from app env

* rm DISABLE_AUTH

* redirect / to /login when not authenticated

* remove TODO

* Update lib/plausible_web/controllers/page_controller.ex

Co-authored-by: Uku Taht <Uku.taht@gmail.com>

* format

Co-authored-by: Uku Taht <Uku.taht@gmail.com>
2022-11-10 12:42:22 +01:00

27 lines
537 B
Elixir

defmodule PlausibleWeb.FirstLaunchPlug do
@moduledoc """
Redirects first-launch users to registration page.
"""
@behaviour Plug
alias Plausible.Release
@impl true
def init(opts) do
_path = Keyword.fetch!(opts, :redirect_to)
end
@impl true
def call(%Plug.Conn{request_path: path} = conn, path), do: conn
def call(conn, redirect_to) do
if Release.should_be_first_launch?() do
conn
|> Phoenix.Controller.redirect(to: redirect_to)
|> Plug.Conn.halt()
else
conn
end
end
end