Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise can't detect :omniauthable, but it's there

I have a RoR application, running the Devise Gem for authentification. For my new API I've implemented the Gem "devise-token-auth": https://github.com/lynndylanhurley/devise_token_auth

Since I want Devise to run for the website and API authentication, I followed the extra tips in the following instruction as well (and als the FAQ of the Gem's Git): http://www.developingandrails.com/2015/02/api-authentication-with-devisetokenauth.html

I've deactivated Devise's :confirmable, but activated :omniauthable. Everything seems to be in place, but I'm getting the following error:

/Users/sebastianplasschaert/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/devise-3.5.2/lib/devise/rails/routes.rb:240:in `block in devise_for': Mapping omniauth_callbacks on a resource that is not omniauthable (ArgumentError)
Please add `devise :omniauthable` to the `User` model

And in my User model I start with the following code:

class User < ActiveRecord::Base


  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :invitable, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable
  include DeviseTokenAuth::Concerns::User

So, :omniauthable seems to be there. When I deactivate:

include DeviseTokenAuth::Concerns::User

then everything works again (but I need it for my API authentication).

Any ideas on what I'm doing wrong?

like image 443
Sebastian Plasschaert Avatar asked Dec 25 '22 07:12

Sebastian Plasschaert


1 Answers

for some reason include DeviseTokenAuth::Concerns::User in removing the omniauthable.

I fixed the issue adding it back:

devise :invitable, :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable,
       :omniauthable
include DeviseTokenAuth::Concerns::User
devise :omniauthable
like image 65
gabrielhilal Avatar answered Jan 06 '23 03:01

gabrielhilal