Added optional basic auth (#31)
This commit is contained in:
1 parent
fdb83ed3f3
commit
c1f30dbd2c
3 files changed
+65
-1
No files matched your search
@@ -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