Search code examples
ruby-on-railsrubydeviseruby-on-rails-5devise-token-auth

Devise_token_auth conflicts?


Made a new API in rails 5 using default --api tag and installed devise_token_auth gem using command rails generate devise_token_auth:install User auth . On doing rake:db:migrate, I get this error undefined method 'devise' for User (call 'User.connection' to establish a connection) which is weird because devise_token_auth is built on top of devise..

So, commenting out routes throws error to user.rb file containing

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable,:omniauthable include DeviseTokenAuth::Concerns::User

After commenting those lines out it throws error to application controller containing: include DeviseTokenAuth::Concerns::SetUserByToken After commenting out this line, I get the devise:orm error.

Also tried adding devise to gemfile and installing devise for users, which failed too, throwing this error again undefined method 'devise' for User (call 'User.connection' to establish a connection)

Expected Migrations to go through,

Getting Devise errors

What should be done to resolve this?

PS- This was a third API I'm making using Devise_token_auth gem, didn't face this issue earlier


Solution

  • This is a devise Issue, ActiveRecord ORM was hard coded inside of the gem before which has been changed now. This can be resolved by creating and adding the devise initializer as mentioned in the below documentation.

    https://devise-token-auth.gitbook.io/devise-token-auth/config/initialization

    There is also another way of fixing this, by adding the following in your user.rb model file.

    extend Devise::Models
    

    There is also an open issue in devise_token_auth

    https://github.com/lynndylanhurley/devise_token_auth/issues/1276

    Where you can follow up regarding this issue / Add in your thoughts for resolving this.