mirror of
https://github.com/plausible/analytics.git
synced 2024-11-28 04:30:42 +03:00
23 lines
446 B
Elixir
23 lines
446 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)
|
|
if user do
|
|
assign(conn, :current_user, user)
|
|
else
|
|
conn
|
|
end
|
|
end
|
|
end
|
|
end
|