I want to override authenticate_user and current_user method of devise gem

前端 未结 5 507
醉梦人生
醉梦人生 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:42

    If you want to add code to authenticate_user!

    class DuckController < ApplicationController
      before_action :authenticate_duck
    
      ...
    
      private
    
      def authenticate_duck
        #use Devise's method
        authenticate_user!
        #add your own stuff
        unless current_user.duck.approved?
          flash[:alert] = "Your duck is still pending. Please contact support for support."
          redirect_to :back
        end
      end
    end
    

提交回复
热议问题