How do I have devise / omniauth redirect to the page from which I signed in from?

别等时光非礼了梦想. 提交于 2019-12-10 10:19:54

问题


I have the authentication through omniauth and that link is available on every page through layout/application.html.haml.

However, when they complete the omniauth authentication, they all go to root.

How can I set it up so they redirect to the actual page from which they clicked on the authentication link (which takes them to the oauth provider).

Thanks


回答1:


You can use request.env['omniauth.origin'].

See https://github.com/intridea/omniauth/wiki/Saving-User-Location




回答2:


I see two options here:

1) Set a session variable on every page you could possibly sign in through like that:

session[:return_to] = request.fullpath

and redirect back to it after signing in:

redirect_to session[:return_to]

or

2) try

redirect_to :back

This depends on how you link your controller actions (haven't worked with omniauth, so I have no experience in that respect)



来源:https://stackoverflow.com/questions/6396863/how-do-i-have-devise-omniauth-redirect-to-the-page-from-which-i-signed-in-from

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