ruby - Rails Devise Token Auth authentication without using email -


i want use 'username' field instead 'email'

i used gems

gem 'devise' gem 'devise_token_auth' 

my model 'user'

devise :database_authenticatable,          :trackable, :registerable, :authentication_keys => [:username]   include devisetokenauth::concerns::user   has_many :projects    def email_required?     false   end    def email_changed?     false   end 

i removed 'validatable'

and tried change model

change_column :users, :email, :string, :null => true remove_index :users, :email 

also set configuration device.rb

config.authentication_keys = [:username] config.case_insensitive_keys = [:username] config.strip_whitespace_keys = [:username] 

but still have error

"email can't blank", "email not email" 

what made wrong? thank you

i found solution

routes.rb

mount_devise_token_auth_for 'user', at: 'auth', :controllers => { :registrations => "registrations" } 

and make registration youself

rails routes have this

                  prefix verb   uri pattern                    controller#action         new_user_session    /auth/sign_in(.:format)        devise_token_auth/sessions#new             user_session post   /auth/sign_in(.:format)        devise_token_auth/sessions#create     destroy_user_session delete /auth/sign_out(.:format)       devise_token_auth/sessions#destroy cancel_user_registration    /auth/cancel(.:format)         registrations#cancel    new_user_registration    /auth/sign_up(.:format)        registrations#new   edit_user_registration    /auth/edit(.:format)           registrations#edit        user_registration patch  /auth(.:format)                registrations#update                          put    /auth(.:format)                registrations#update                          delete /auth(.:format)                registrations#destroy                          post   /auth(.:format)                registrations#create      auth_validate_token    /auth/validate_token(.:format) devise_token_auth/token_validations#validate_token 

can use methods

- valid_token? - create_new_auth_token - build_auth_header 

look

https://github.com/lynndylanhurley/devise_token_auth

unpermitted parameters adding new fields devise in rails 4.0

also can delete email validation devise_token_auth

add file config/initializers/change_email_valid_devise_token_auth.rb

emailvalidator.class_eval   def validate_each(record, attribute, value)   end end 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -