Anyway I can use this in Phoenix router definition?
Closed this issue · 3 comments
ChrisZou commented
Hi @paulanthonywilson ,
First of all, thank you so much for making this library. It has been great help for me.
I wonder if could use this in my Phoenix router definition? I would like to apply basic auth for a certain router scope, so that I don't have to write the plug code in every controller under that scope.
Sort of like this.
defmodule MyApp.Router do
use MyApp, :router
pipeline :admin_auth do
plug(:basic_auth, ...)
end
scope "/admin", as: :admin do
pipe_through([:browser, :admin_auth])
# My router definition
end
Thank you!
picandocodigo commented
Hi @ChrisZou,
You can use it in a Phoenix router definition. I've used it like this in a Phoenix app's router:
pipeline :authentication do
plug BasicAuth, use_config: {:web, :authentication}
end
scope "/", Web do
pipe_through [:browser, :authentication]
get "/", PageController, :index
end
And I used it in a learning project with a similar example here.
paulanthonywilson commented
Seems to be covered.
ChrisZou commented
@picandocodigo Thank you! It works. I guess I don't understand plug enough and didn't read the doc carefully enough. 😅