redirect back to current page using omniauth and devise

匆匆过客 提交于 2019-12-19 11:57:41

问题


I want to redirect back to current page after oauth signin, and I followed this Devise wiki and did the following:

  def after_sign_in_path_for(resource)
    sign_in_url = new_user_session_url
    if request.referer == sign_in_url
      super
    else
      request.env['omniauth.origin'] || stored_location_for(resource) || request.referer || root_path
    end
  end

request.env['omniauth.origin'] is http://www.bubutravel.com/users/sign_in

stored_location_for(resource) is nil

request.referer is http://openapi.qzone.qq.com/oauth/[omitted] (my provider)

So after my omniauth login, I get redirected to the provider urls again.

Is the wiki outdated? What's the recommended way to do omniauth login redirect to current page?


回答1:


I realized that I should not override after_sign_in_path_for as suggested by the wiki. I should just record the path in every request:

  before_action :store_current_location, :unless => :devise_controller?
  def store_current_location
    store_location_for(:user, request.url)
  end

And the build-in after_sign_in_path_for will handle the rest.



来源:https://stackoverflow.com/questions/26543503/redirect-back-to-current-page-using-omniauth-and-devise

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