Authenticating the engine mount with custom Rails auth #1076
-
Hi, I could use some advice. Typically, when you roll your own Rails auth, you use
The only thing we'd need to check is It seems that a solution for this would fit the philosophy of the project of being very Rails-centric. What are your thoughts? Perhaps there's an existing configuration I missed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I'll sympathize that I think Rails Engines could make it simpler. Most straightforwardly, my recommendation would be to copy your user session code into an initializer where you mix it into # config/initializers/good_job.rb
module GoodJobAuthentication
extend ActiveSupport::Concern
included do
before_action do
raise ActionController::RoutingError.new('Not Found') unless current_user&.admin?
end
end
def current_user
# load your user out of the session
end
end
Rails.application.reloader.to_prepare do
GoodJob::ApplicationController.include(GoodJobAuthentication)
end That |
Beta Was this translation helpful? Give feedback.
I'll sympathize that I think Rails Engines could make it simpler.
Most straightforwardly, my recommendation would be to copy your user session code into an initializer where you mix it into
GoodJob::ApplicationController
. To be DRYer, you could extract the user session code to a module, and then mix it into both yourApplicationController
andGoodJob::ApplicationController
. Something like this: