Added optional basic auth (#31)

This commit is contained in:
Kieran
2024-02-21 11:25:25 -08:00
committed by GitHub
parent fdb83ed3f3
commit c1f30dbd2c
3 changed files with 65 additions and 1 deletions
+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