I want to override authenticate_user and current_user method of devise gem

前端 未结 5 519
醉梦人生
醉梦人生 2020-12-16 15:22

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

5条回答
  •  被撕碎了的回忆
    2020-12-16 15:46

    You have to create a custom class to override the default Devise behavior:

      class CustomFailure < Devise::FailureApp
        def redirect_url
          #return super unless [:worker, :employer, :user].include?(scope) #make it specific to a scope
           new_user_session_url(:subdomain => 'secure')
        end
    
        # You need to override respond to eliminate recall
        def respond
          if http_auth?
            http_auth
          else
            redirect
          end
        end
      end
    

    And in your config/initializers/devise.rb:

      config.warden do |manager|
        manager.failure_app = CustomFailure
      end
    

    But I suggest check out the Devise documentation :)

    https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

提交回复
热议问题