Added optional basic auth (#31)

This commit is contained in:
Kieran authored and GitHub committed 2024-02-21 17:37:25 -08:00
1 parent e3f1b409b9
commit 3efc533fb7
3 files changed
+65 -1

No files matched your search

+12
View File
@@ -2,6 +2,7 @@ defmodule PinchflatWeb.Router do
use PinchflatWeb, :router
pipeline :browser do
plug :basic_auth
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
@@ -48,4 +49,15 @@ defmodule PinchflatWeb.Router do
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
defp basic_auth(conn, _opts) do
username = Application.get_env(:pinchflat, :basic_auth_username)
password = Application.get_env(:pinchflat, :basic_auth_password)
if username && password do
Plug.BasicAuth.basic_auth(conn, username: username, password: password, realm: "Pinchflat")
else
conn
end
end
end