mirror of
https://github.com/plausible/analytics.git
synced 2024-11-28 13:02:53 +03:00
7683839de1
* Show past due subscription in user settings * Users who are past due keep their access * Add more info in the past due banner * Show cancelled subscription plan * Add init admin back into test suite * Make sure users have access to their stats until the end of billing cycle * Fix free subscription bug * Ensure the latest subscription is loaded
28 lines
611 B
Elixir
28 lines
611 B
Elixir
defmodule PlausibleWeb.AuthPlug do
|
|
import Plug.Conn
|
|
use Plausible.Repo
|
|
|
|
def init(options) do
|
|
options
|
|
end
|
|
|
|
def call(conn, _opts) do
|
|
case get_session(conn, :current_user_id) do
|
|
nil ->
|
|
conn
|
|
|
|
id ->
|
|
user =
|
|
Repo.get_by(Plausible.Auth.User, id: id)
|
|
|> Repo.preload(subscription: from(s in Plausible.Billing.Subscription, order_by: [desc: s.inserted_at]))
|
|
|
|
if user do
|
|
Sentry.Context.set_user_context(%{id: user.id, name: user.name})
|
|
assign(conn, :current_user, user)
|
|
else
|
|
conn
|
|
end
|
|
end
|
|
end
|
|
end
|