Is it possible to examine user in route constraint?
Envek opened this issue · 2 comments
Envek commented
Hello.
Is it possible to examine users before allowing them access to some not controlled Rack application in Rails routes?
For example:
require 'sidekiq/web'
require "monban/constraints/signed_out"
Rails.application.routes.draw do
constraints Monban::Constraints::SignedIn.new do
# let Sidekiq dashboard to be available only for some kind of admins
# e.g. if user.admin? or anything
mount Sidekiq::Web => '/sidekiq'
# end
end
end
Envek commented
Found it in Rails guides about routing:
require 'sidekiq/web'
require "monban/constraints/signed_in"
Rails.application.routes.draw do
constraints Monban::Constraints::SignedIn.new do
# let Sidekiq dashboard to be available only for some kind of admins
mount Sidekiq::Web => '/sidekiq', constraints: -> (request) { request.env['warden'].user.system_admin? }
end
end
Sorry for inconvenience and thank you for Monban!
halogenandtoast commented
No problem, glad you found a solution!