Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to override authenticate_user and current_user method of devise gem

I want to override authenticate_user! and current_user method of devise gem in my application Controller can you please help me with regards to that Thanks

like image 413
Syed Raza Avatar asked Jun 21 '11 12:06

Syed Raza


2 Answers

You may be able to monkey-patch it like:

module Devise
  module Controllers
    module Helpers
      def authenticate_user!
        #do some stuff
      end
    end
  end
end   

But I would ask what the ultimate goal is, because Devise has some customizability built into it already, and overriding these methods makes me wonder "why use Devise at all?"

like image 196
Sammy Larbi Avatar answered Oct 07 '22 04:10

Sammy Larbi


On overriding how a user is authenticated:

Devise uses Warden under the hood https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb

So you can just add a new strategy in Warden to authenticate your users. See https://github.com/hassox/warden/wiki/Strategies

You should not need to override current_user. What challenge are you facing ? Do you need a different model returned ?

like image 30
Monica Wilkinson Avatar answered Oct 07 '22 03:10

Monica Wilkinson