9d5176e2b66953a3fd50bb77fbc87b5d8cfd957a
[akkoma] / lib / pleroma / plugs / ensure_authenticated_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.EnsureAuthenticatedPlug do
6 import Plug.Conn
7 import Pleroma.Web.TranslationHelpers
8
9 alias Pleroma.User
10
11 use Pleroma.Web, :plug
12
13 def init(options) do
14 options
15 end
16
17 @impl true
18 def perform(%{assigns: %{user: %User{}}} = conn, _) do
19 conn
20 end
21
22 def perform(conn, _) do
23 conn
24 |> render_error(:forbidden, "Invalid credentials.")
25 |> halt()
26 end
27 end