0

我按照此处的步骤操作,在合并帐户时遇到了一些问题

根据说明,我将以下方法添加到我的 ApplicationController

def after_sign_in_path_for(resource)
  # Merge data from Facebook with her current account
  if session["facebook_data"] && current_user.facebook_uid.nil?
    current_user.facebook_uid = session["facebook_data"]["uid"]
    current_user.save(:validate => false)
  end

  # Countermeasure against session fixation
  session.keys.grep(/^facebook\./).each { |k| session.delete(k) }

  super
end

但是,我在 ApplicationController 中得到了一个空会话 ["facebook_data"],即使我在调用此方法的回调 app/controllers/users/omniauth_callbacks_controller.rb 中看到了正确的会话值:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)
    if user && user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
      sign_in_and_redirect user, :event => :authentication
    else
      session["facebook_data"] = env["omniauth.auth"]
      redirect_to new_user_session_url # this redirect invokes the after_sign_in_path_for method in ApplicationController
    end
  end

end

我在这里想念什么?

4

1 回答 1

0

在众多原因中,有两个原因值得检查:

1)session["facebook_data"] in 在被ApplicationController设置之前被调用omniauth_callbacks_controller.rb

解决方案:检查两个控制器的调用是否正确同步,

  • 它应该是 firstomniauth_callbacks_controller.rb然后ApplicationController

2)的值在设置后session["facebook_data"]重置为omniauth_callbacks_controller.rb

解决方案:跟踪session["facebook_data"]设置值之后的omniauth_callbacks_controller.rb调用直到调用session["facebook_data"]in ApplicationController

于 2013-01-25T09:21:52.080 回答