How to use Devise to protect delayed_job_web interface?

I am using delayed_job_web stone to track pending jobs. https://github.com/ejschmitt/delayed_job_web

Accessible via this line on my routes. rb:

match "/delayed_job" => DelayedJobWeb, :anchor => false 

Every other area of ​​my site requires a login using the Devise gem. How do I do this, also need to log in?

In readme, they suggest adding the following to config.rb:

 if Rails.env.production? DelayedJobWeb.use Rack::Auth::Basic do |username, password| username == 'username' password == 'password' end end 

But it just uses authentication with a regular text browser.

UPDATE: I tried something similar to railscast on resque, and I think it is on the verge of work, but now it gives me a redirect loop:

  authenticate :admin do mount DelayedJobWeb, :at => "/delayed_job" end 

Any thoughts on why it should give a redirect loop?

Thanks,

+7
source share
3 answers

Use authenticated instead of authenticate as described here: http://excid3.com/blog/rails-tip-5-authenticated-root-and-dashboard-routes-with-devise/

It works for me!

+6
source

You can do something like this to define this inside the config/routes.rb file

  authenticate_user = lambda do |request| request.env['warden'].authenticate? end constraints authenticate_user do mount DelayedJobWeb, :at => "/delayed_job" end 

Alternatively, if you have a cancan for any other role management library, you can do something like this

I used both of these methods in my applications to control access to resque-web depending on the needs of the application

Hope for this help

+1
source

Now in 2017, I tried other solutions and they did not work, but the following administrator check works:

 authenticated :user, -> user { user.admin? } do mount DelayedJobWeb, at: "/delayed_job" end 
0
source

All Articles