aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/plugs/ensure_authenticated_plug.ex19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/pleroma/plugs/ensure_authenticated_plug.ex b/lib/pleroma/plugs/ensure_authenticated_plug.ex
new file mode 100644
index 000000000..bca44eb2c
--- /dev/null
+++ b/lib/pleroma/plugs/ensure_authenticated_plug.ex
@@ -0,0 +1,19 @@
+defmodule Pleroma.Plugs.EnsureAuthenticatedPlug do
+ import Plug.Conn
+ alias Pleroma.User
+
+ def init(options) do
+ options
+ end
+
+ def call(%{assigns: %{user: %User{}}} = conn, _) do
+ conn
+ end
+
+ def call(conn, _) do
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Jason.encode!(%{error: "Invalid credentials."}))
+ |> halt
+ end
+end