other files consistency
[akkoma] / lib / pleroma / plugs / session_authentication_plug.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.SessionAuthenticationPlug do
6 import Plug.Conn
7
8 def init(options) do
9 options
10 end
11
12 def call(conn, _) do
13 with saved_user_id <- get_session(conn, :user_id),
14 %{auth_user: %{id: ^saved_user_id}} <- conn.assigns do
15 conn
16 |> assign(:user, conn.assigns.auth_user)
17 else
18 _ -> conn
19 end
20 end
21 end