Devise: Omniauthable and Single Table Inheritance (STI)

Created on 18 Jun 2012  路  6Comments  路  Source: heartcombo/devise

Hello,

In my app I had two models with devise authentication: User and Admin. They both need Facebook login. So after reading in the wiki:

Currently, Devise only allows you to make one model omniauthable

I refactored my project to use STI, so now I have User and Admin inherits from User. My surprise came when after setting everything for Omniauth (following the wiki above) I got this error:

/Users/javi/.rvm/gems/ruby-1.9.2-p180/gems/devise-2.1.0/lib/devise/rails/routes.rb:384:in `devise_omniauth_callback': Wrong OmniAuth configuration. If you are getting this exception, it means that either: (RuntimeError)

1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one
2) You are setting :omniauthable in more than one model
3) You changed your Devise routes/OmniAuth setting and haven't restarted your server

I am not setting :omniauthable in more than one model, I just have :omniauthable in the parent User model. If I remove the Admin class everything works fine. So, is there any workaround for this? Perhaps the error and the wiki should be more specific on this?.

Thanks in advance.

Most helpful comment

Sorry, reading this better, it is actually a Devise error. The issue is that you are calling devise_for for different models containing :omniauthable. Your best approach is to simply not use devise omniauthable and use omniauth on your own (it should not be a big issue, devise's :omniauthable is simply a thin wrapper around omniauth that generates a couple routes for you).

All 6 comments

use the mailing list or stack overflow for questions

Sorry, reading this better, it is actually a Devise error. The issue is that you are calling devise_for for different models containing :omniauthable. Your best approach is to simply not use devise omniauthable and use omniauth on your own (it should not be a big issue, devise's :omniauthable is simply a thin wrapper around omniauth that generates a couple routes for you).

You're right. I had two devise_for in my routes.rb (legacy from my code previous refactoring and using STI). Removing the devise_for :admins, fixes the issue.

I'll keep using devise since I do want registration without FB.

Thank you for your quick response.

I mean, you can continue using devise for everything. Just handle the omniauth part without devise (without including omniauthable but manually including omniauth middleware and so on).

any work around of this problem yet ? how to handle the omniauth part without devise ? what things needed for it? route settings ?

Just don't include :omniauthable in Devise and follow the instructions on omniauth website/docs/tutorial about integrating with rails.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jroggeman picture jroggeman  路  3Comments

edipox picture edipox  路  4Comments

Pedroknoll picture Pedroknoll  路  3Comments

mikeki picture mikeki  路  4Comments

afuno picture afuno  路  3Comments