Method: Devise::Models::Authenticatable::ClassMethods#find_for_authentication

Defined in:
lib/devise/models/authenticatable.rb

#find_for_authentication(tainted_conditions) ⇒ Object

Find first record based on conditions given (ie by the sign in form). This method is always called during an authentication process but it may be wrapped as well. For instance, database authenticatable provides a `find_for_database_authentication` that wraps a call to this method. This allows you to customize both database authenticatable or the whole authenticate stack by customize `find_for_authentication.`

Overwrite to add customized conditions, create a join, or maybe use a namedscope to filter records while authenticating. Example:

def self.find_for_authentication(tainted_conditions)
  find_first_by_auth_conditions(tainted_conditions, active: true)
end

Finally, notice that Devise also queries for users in other scenarios besides authentication, for example when retrieving a user to send an e-mail for password reset. In such cases, find_for_authentication is not called.


270
271
272
# File 'lib/devise/models/authenticatable.rb', line 270

def find_for_authentication(tainted_conditions)
  find_first_by_auth_conditions(tainted_conditions)
end