简体   繁体   English

将Devise与Ruby on Rails一起使用,如果用户使用无效的auth_token,如何将用户发送到sign_in路径?

[英]Using Devise with Ruby on Rails, how can I send the user to sign_in path if they use an invalid auth_token?

When I send a user to /dashboard?auth_token=XXX , and the auth_token is incorrect, the user gets taken to the root_path . 当我将用户发送到/dashboard?auth_token=XXX ,并且auth_token不正确时,用户将被带到root_path

In this situation, I want the user to be taken to the sign_in path, and then be taken to /dashboard after they sign in. How can I do this? 在这种情况下,我希望用户被带到sign_in路径,然后在他们登录后被带到/dashboard 。我该怎么做?

The default in Devise is to redirect to "new_#{scope}_session_path" route if one is available. Devise中的默认值是重定向到“new _#{scope} _session_path”路由(如果有)。 As seen here: 如下所示:

https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb#L89 https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb#L89

So, assuming you are using the user scope, be sure you have a new_user_session_path defined by your router. 因此,假设您使用的是用户范围,请确保路由器已定义new_user_session_path

About redirecting back to the original page, try out this wiki page: 关于重定向回原始页面,请试用此Wiki页面:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in

Notice the filter in the wiki page needs to be added before you invoke Devise's authentication filters. 请注意,在调用Devise的身份验证过滤器之前,需要添加Wiki页面中的过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails:无法使用Devise对用户进行签名 - Rails: Unable to sign_in a user using Devise 使用devise auth_token的Rails API注销已登录的用户 - Rails API using devise auth_token logs out logged in user 使用Devise,如何将根页面设置为如果用户注销则不重定向到“ sign_in”页面? - Using Devise, how can I set the root page to not redirect to the “sign_in” page if the user is logged out? 设计-auth_token和current_user - Devise - auth_token and current_user 如何将Rails devSign_in路径设置为根URL - How to set rails devise sign_in path as a root url rails 3设计避免访问/ sign_in路径 - rails 3 devise avoid access /sign_in path 在Rails中设计电子邮件确认后如何登录用户 - How to sign_in user after devise email confirmation in Rails 在使用Devise的rails应用程序中,当未登录的用户访问root时,他们被重定向到/ users / sign_in而不是root路径吗? - In my rails app using Devise, when an unsigned in user visits root they are redirected to /users/sign_in instead of the root path? 通过Devise的iOS用户登录会话,但未保留Auth_token - iOS User Login Session via Devise but Auth_token not kept 使用请求标头的auth_token而不是Rails 3 / devise的POST / PUT参数 - Using auth_token from request headers instead from POST/PUT parameters with Rails 3 / devise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM