I can register a user getting both email address and mobile number in my application. But what I really want is to register user using either email or mobile as a primary authen
Yes, you can do easily with minor setting.
like this
Modify your application_controller.rb
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
added_attrs = [:mobile_no, :email, :password, :password_confirmation, :remember_me]
devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
devise_parameter_sanitizer.permit :account_update, keys: added_attrs
end
end
Create a login virtual attribute in the User model
Add login as an attr_accessor:
# Virtual attribute for authenticating by either username or email
# This is in addition to a real persisted field like 'username'
attr_accessor :login
or, if you will use this variable somewhere else in the code:
def login=(login)
@login = login
end
def login
@login || self.mobile_no || self.email
end
Modify config/initializers/devise.rb to have:
config.authentication_keys = [ :login ]
You can refer this link for more reference.
https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address