我想在 oauth 登录后重定向回当前页面,我遵循了这个 Devise wiki并执行了以下操作:
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
Run Code Online (Sandbox Code Playgroud)
request.env['omniauth.origin']是http://www.bubutravel.com/users/sign_in
stored_location_for(resource) 是零
request.referer是http://openapi.qzone.qq.com/oauth/[omitted](我的提供者)
因此,在我的 omniauth 登录后,我再次被重定向到提供程序的 URL。
维基过时了吗?将 omniauth 登录重定向到当前页面的推荐方法是什么?
我意识到我不应该after_sign_in_path_for按照维基的建议进行覆盖。我应该在每个请求中记录路径:
before_action :store_current_location, :unless => :devise_controller?
def store_current_location
store_location_for(:user, request.url)
end
Run Code Online (Sandbox Code Playgroud)
内置after_sign_in_path_for将处理其余的。
| 归档时间: |
|
| 查看次数: |
1089 次 |
| 最近记录: |