首页 > 解决方案 > Clear session store for a specific user in rails

问题描述

I am using the session_store cookie_store to save the sessions of my rails 4 application. Here my code

Rails.application.config.session_store :cookie_store, key: '_app_session'

My question is how can I invalidate the session of a specific user?

标签: ruby-on-rails

解决方案


您只能使当前用户的会话无效 - 通过调用reset_session使他们的会话 ID 无效。

服务器不知道哪些会话 id 使用 cookie_store 链接到什么(数据库)用户 id。它只是跟踪有效会话标识符的列表。如果 cookie 中提供的会话标识符是有效的,那么 Rails 将解密并反序列化会话存储 cookie。这是存储用户 ID 的地方。由于用户 ID 由客户端存储,因此无法遍历会话存储并从用户 ID 中找到会话标识符。

如果您想密切关注用户会话,则需要使用不同的系统,例如使用 memcached 或数据库会话存储或访问令牌授予。


推荐阅读