Omniauth “with” STI and devise

三世轮回 提交于 2019-12-21 23:59:58

问题


I'm figured out with no results. I have a model named User and to models with STI fan and artist, like this:

class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable, :confirmable, :lockable,
     :recoverable, :rememberable, :trackable, :validatable, **:omniauthable**
end

and my others models

Class Artist < User end
Class Fan < User end

my routes

devise_for :users
devise_for :artists
devise_for :fans

I have a problem when try to run my server or anything else i got this error

Wrong OmniAuth configuration. If you are getting this exception, it means that either:

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

my app is advanced and don't wanna go back and refactor it, any help will appreciate


回答1:


The answer can be found here.

Devise gets mixed up since you are calling devise_for for three different models and one of them is using the omniauthable module.

Either:

  1. Remove all devise_for methods except for :users.

  2. Or remove the omniauthable module from the user model, create your own omniauth routes and stop using devise's middleware by moving your omniauth configuration into a new file. So, instead of having this in devise.rb:

    Devise.setup do |config|
      config.omniauth :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
    end
    

    You now have this in your new file omniauth.rb:

    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
    end
    

    The Railscast on Simple OmniAuth should help you setting this up.



来源:https://stackoverflow.com/questions/13567113/omniauth-with-sti-and-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!