Rails的Omniauth Facebook登录重定向到注册(Rails Omniauth Fac

2019-10-20 04:39发布

由于某种原因,我Omniauth Facebook登录被重定向到/用户/ sign_up#= -但除此之外,似乎是工作。 我有这个在routes.rb中:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

我有这样的application.html.erb:

 <%= link_to "", user_omniauth_authorize_path(:facebook, :origin=>"root_url") %> 
                      <%= link_to(image_tag("FB-Login.png"),    
 user_omniauth_authorize_path(:facebook), :origin=>"root_url", class:"mycss") %>

我有这样的application_controller.rb:

def after_sign_in_path_for(resource_or_scope)
      Rails.logger.level = 0 
      logger.debug "after_sign_in_path_for"
          logger.debug "Session: #{@session.inspect}"
      logger.debug "omniauth.origin: #{omniauth.origin}"
          logger.debug "root_url: #{root_url}"
    ##  if request.env['omniauth.origin']
##    request.env['omniauth.origin']
      request.env['omniauth.origin'] || root_url
  end

有趣的是,日志报表未显示在Heroku的日志 - 看起来像after_sign_in_path_for不叫?

任何帮助表示赞赏,斯拉夫科

Answer 1:

也许该用户已经存在?

尝试检查用户的存在之前,持久性:

def facebook
  @user = User.from_omniauth(request.env["omniauth.auth"])
  if @user
    sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
    set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
  else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end


文章来源: Rails Omniauth Facebook login redirects to sign up