【问题标题】:Devise Omniauth facebook redirect flash message error设计 Omniauth facebook 重定向 flash 消息错误
【发布时间】:2016-11-24 22:26:23
【问题描述】:

我使用 Devise 和omniauth 创建了一个rails 应用程序来注册fb。 一切正常,但是当我在注册后重定向到最后一页时,我在来自 fb 的用户的 Flash 消息中出现错误。

这是我的 application_controller

def set_redirect_path
  @redirect_path = request.path
end

def after_sign_in_path_for(resource)
  if params[:redirect_to].present?
    store_location_for(resource, params[:redirect_to])
  elsif request.referer == new_session_url(:user)
    super
  else
    request.env['omniauth.origin'] || stored_location_for(resource) || request.referer || root_path
  end
end

这里是omniauth_callbacks_controller

def facebook
    @user = User.from_omniauth(request.env["omniauth.auth"])    

    if @user.persisted?
        sign_in_and_redirect @user, :event => :authentication
        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

def failure
    redirect_to root_path
end

我在注册并从 facebook 重定向后收到的 flash 消息是 already_authenticated 错误,上面写着“您已经登录。”

有谁知道我该如何解决这个问题

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby devise omniauth-facebook


    【解决方案1】:

    解决方法是改变 after_sign_in_path_for 方法。例如在 ApplicationController 中:

    def after_sign_in_path_for(resource)
        super resource
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 2014-05-23
      • 2012-03-05
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2015-07-22
      • 1970-01-01
      相关资源
      最近更新 更多