0

我目前正在处理 422 错误(无效的身份验证令牌已传递给 rails),并且我目前将用户重定向到单独的页面。这很好用,但我发现如果用户登录并在该登录请求期间遇到 422 错误,则用户转到单独的页面并且现在已登录。理想情况下,我希望用户不要登录.

我目前使用 Devise(3.4.1) 进行身份验证。在下面编写的代码之外没有编写任何自定义代码。

当用户遇到 422 错误且未登录时,如何防止用户登录?

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  # This method is called whenever a CSRF token is invalid.
  def handle_unverified_request
    # By default this method raises ActionController::InvalidAuthenticityToken
    redirect_to '/422'
  end
end
4

1 回答 1

0

尝试这个

def handle_unverified_request
  super # call the default behaviour, including Devise override
  authenticate_user!
end
于 2016-12-30T19:54:22.907 回答