Customise sorcery's require_login function

420 Views Asked by At

Is there a way to customise sorcery's require_login function to provide a flash message and to redirect to page other than root_path e.g. to a login page?

1

There are 1 best solutions below

0
Obromios On BEST ANSWER

This can be done by overriding sorcery's not_authenticated function, which it calls when the user is not logged in, for example

app/controller/application_controller.rb

class ApplicationController < ActionController::Base
  before_action :require_login

  def not_authenticated
    flash[:alert] = 'Customised warning'
    redirect_to main_app.login_path
  end

end

Also make sure that the rails_admin controllers are inheriting from your application controller;

config/initializers/rails_admin.rb

RailsAdmin.config do |config| ... config.parent_controller = 'ApplicationController' end