Skip to content

Authenticating the engine mount with custom Rails auth #1076

Answered by bensheldon
maxim asked this question in Q&A
Discussion options

You must be logged in to vote

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 your ApplicationController and GoodJob::ApplicationController. Something like this:

# 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
e…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@maxim
Comment options

@maxim
Comment options

@bensheldon
Comment options

@maxim
Comment options

@bensheldon
Comment options

Answer selected by maxim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants