'Rails - Devise gem - Add one more check during login

I am using devise gem. I would like to add one more condition check while the user clicks in login button. So far I haven't customized create method in the sessions controller.

I would like to add a condition like if user.valid? There is one field called valid in the database. What is the best way to do this with devise?

Any guidance or help would be appreciated



Solution 1:[1]

Check this documentation, the main idea is to override active_for_authentication?.

class User < ActiveRecord::Base
  def active_for_authentication?
    super && special_condition_is_valid?
  end
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Christos-Angelos Vasilopoulos