Ruby on Rails中如何处理设计注销时无效的真实性令牌问题?

更新于
2026-10-09 20:24:39
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计263个文字,预计阅读时间需要2分钟。

Ruby on Rails中如何处理设计注销时无效的真实性令牌问题?

用户可在myapp.com上登录,并将域名重定向到子域,如username.myapp.com。这有效,因为配置了session_store为cookie_store,key为'domain_session',domain为':all'。

我的用户可以在myapp.com上登录,并将其重定向到他们的子域,例如username.myapp.com

这是有效的,因为我有

Downhill::Application.config.session_store :cookie_store, :key => '_domain_session', :domain => :all

在session_store.rb&我的应用程序控制器中的一个方法,它根据用户名检查子域(因此您无法登录到其他用户的子域).

出于测试目的,username.myapp.com和myapp.com都会在登录后显示用户的数据.

问题是:当用户从username.myapp.com注销时,他们会得到

Ruby on Rails中如何处理设计注销时无效的真实性令牌问题?

ActionController::InvalidAuthenticityToken in Devise::SessionsController#destroy

但是:当他们从myapp.com退出时,它就会退出.

有任何想法吗?

编辑

我已经覆盖了after_sign_out_path_for和after_sign_in_path_for

def after_sign_out_path_for(resource) root_url end def after_sign_in_path_for(resource) dashboard_url(:subdomain => current_user.subdomain) end 我认为您的应用程序布局中缺少此行

<%= csrf_meta_tags %>

本文共计263个文字,预计阅读时间需要2分钟。

Ruby on Rails中如何处理设计注销时无效的真实性令牌问题?

用户可在myapp.com上登录,并将域名重定向到子域,如username.myapp.com。这有效,因为配置了session_store为cookie_store,key为'domain_session',domain为':all'。

我的用户可以在myapp.com上登录,并将其重定向到他们的子域,例如username.myapp.com

这是有效的,因为我有

Downhill::Application.config.session_store :cookie_store, :key => '_domain_session', :domain => :all

在session_store.rb&我的应用程序控制器中的一个方法,它根据用户名检查子域(因此您无法登录到其他用户的子域).

出于测试目的,username.myapp.com和myapp.com都会在登录后显示用户的数据.

问题是:当用户从username.myapp.com注销时,他们会得到

Ruby on Rails中如何处理设计注销时无效的真实性令牌问题?

ActionController::InvalidAuthenticityToken in Devise::SessionsController#destroy

但是:当他们从myapp.com退出时,它就会退出.

有任何想法吗?

编辑

我已经覆盖了after_sign_out_path_for和after_sign_in_path_for

def after_sign_out_path_for(resource) root_url end def after_sign_in_path_for(resource) dashboard_url(:subdomain => current_user.subdomain) end 我认为您的应用程序布局中缺少此行

<%= csrf_meta_tags %>