![](/img/trans.png)
[英]Getting ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken) error for devise sign in and sign up
[英]Devise error - ActionController::InvalidAuthenticityToken
在管理员和用户登录同一页面时,在设计登出时出现问题
例如,我在chrome浏览器中以用户身份登录,而在同一浏览器中以admin身份登录,当我退出admin会话时,该用户会话会自动注销并重定向到登录页面。
当我尝试以用户身份登录时,它已成功登录并进入管理员登录页面并尝试登录,它显示-
ActionController::InvalidAuthenticityToken
我今天有同样的问题。 以防万一,我想分享我找到的一种解决方案。 在阅读设备回购中的这个问题后,我有了这个主意: https : //github.com/plataformatec/devise/issues/3461
class Identities::SessionsController < Devise::SessionsController
rescue_from ActionController::InvalidAuthenticityToken, with: :force_log_out
#...
def force_log_out
return unless params[:action] == 'destroy'
puts "rescued ActionController::InvalidAuthenticityToken"
puts "force log out and redirect back to '/'"
sign_out_all_scopes
redirect_to '/'
end
# ...
我不知道这是否是最好的解决方案。 如果有人有其他解决方案,我想学习。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.