2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.AuthPlug do
|
|
|
|
import Plug.Conn
|
2019-09-11 19:04:37 +03:00
|
|
|
use Plausible.Repo
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
def init(options) do
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(conn, _opts) do
|
2022-10-18 18:11:30 +03:00
|
|
|
with id when is_integer(id) <- get_session(conn, :current_user_id),
|
2023-08-02 14:45:49 +03:00
|
|
|
%Plausible.Auth.User{} = user <- Plausible.Users.with_subscription(id) do
|
2022-10-18 18:11:30 +03:00
|
|
|
Plausible.OpenTelemetry.add_user_attributes(user)
|
|
|
|
Sentry.Context.set_user_context(%{id: user.id, name: user.name, email: user.email})
|
|
|
|
assign(conn, :current_user, user)
|
|
|
|
else
|
|
|
|
nil -> conn
|
|
|
|
end
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|