Add SessionAuthenticationPlug.
This commit is contained in:
parent
a3f54fca4d
commit
9a96c93be7
2 changed files with 77 additions and 0 deletions
18
lib/pleroma/plugs/session_authentication_plug.ex
Normal file
18
lib/pleroma/plugs/session_authentication_plug.ex
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
defmodule Pleroma.Plugs.SessionAuthenticationPlug do
|
||||
import Plug.Conn
|
||||
alias Pleroma.User
|
||||
|
||||
def init(options) do
|
||||
options
|
||||
end
|
||||
|
||||
def call(conn, _) do
|
||||
with saved_user_id <- get_session(conn, :user_id),
|
||||
%{auth_user: %{id: ^saved_user_id}} <- conn.assigns do
|
||||
conn
|
||||
|> assign(:user, conn.assigns.auth_user)
|
||||
else
|
||||
_ -> conn
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue