Added optional basic auth (#31)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user