Search code examples
ruby-on-railsauthenticationruby-on-rails-3ruby-on-rails-pluginsdevise

How to make use of "username or Email", to login in devise?


I found a way to customize devise to use username to login instead of email address.
But actually I want to use combination :-

Enter username or Email:   <text-box>
Enter your password    :   <text-box>  

So how to achieve this ?

Actually we need to modify devise gem's configuration to support this.
for now I know that modifying the "/config/initializers/devise.rb" file as

config.authentication_keys = [ :username ] (edited from email to username.)  

would actually enable logging in using username instead of emailid.
But can I do some thing like:-

config.authentication_keys = [ :username | :email] in the "config/initializers/devise.rb" file.  

So that we devise can take username or email as authentication key at runtime depending on the input provided by user.
Thanks in advance .


Solution

  • Look at there : https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address (url updated)

    It explains how to allow users to sign in using their username or email address.