Check if user is active before allowing user to sign in with devise (rails) Check if user is active before allowing user to sign in with devise (rails) ruby ruby

Check if user is active before allowing user to sign in with devise (rails)


Add these two methods to your user model, devise should pick them up automatically - you should NOT need to extend Devise::SessionsController

def active_for_authentication?  super && self.your_method_for_checking_active # i.e. super && self.is_activeenddef inactive_message  "Sorry, this account has been deactivated."end


Devise (If you have devise 3.2+) now support block parameter in (session) create

# assuming this is your session controllerclass SessionsController < Devise::SessionsControllerdef create  super do |resource|     unless resource.active?      sign_out      # you can set flash message as well.      redirect_to :sorry_not_active_url      return    end  endend