devise: before_action :authenticate_user! not working

I am unable to get before_action :authenticate_user! to work in my controllers which inherit from Devise.

class RegistrationsController < Devise::RegistrationsController
  before_action :authenticate_user!
  def hello_world
    redirect_to pricing_path
  end
end

before_action :authenticate_user! works as expected in the other controllers.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

@ce07c3 @jmuheim @alexisraca I ran in to this today as well. The following worked for me (the trick is force: true):

class RegistrationsController < Devise::RegistrationsController
  before_action ->{ authenticate_user!(force: true) }

  ...
end

I found one more solution which is worked for me:

class RegistrationsController < Devise::RegistrationsController
  prepend_before_action :authenticate_scope!

  ...
end