ruby-on-railsrubyauthenticationrails-enginesclearance

Authenticating engines using Clearance in main app


Context

I want to run several rails applications on the same server, by implementing them as engines in a main application. The main application should contain authentication logic, such as users and roles.


Problem

I am using clearance, by Thoughbot, for my user system, but when I want to authenticate an engine by using before_action :require_login in its controllers, I get the following error:

ActionController::UrlGenerationError in MyEngine::PagesController#index. No route matches {:action => "new", :controller => "clearance/sessions"}

I understand this is because the engine is looking for clearance controllers inside its namespace, but how do I get the engine to look in the main application? Is there an easy fix to this which is flexible enough to not be a hassle when adding new engines to the system?

Edit:

I have already tried inheriting from the main app ApplicationController, by doing

class ApplicationController < ::ApplicationController


Solution

  • You can trace the code in lib/clearance/authorization.rb to look for methods to override or configure.

    In this case, it looks like you want to override sign_in_url so that the resulting URL points to your host app.