提问人:bkunzi01 提问时间:11/16/2023 最后编辑:bkunzi01 更新时间:11/16/2023 访问量:17
Redis Session_Store 在从 Rails 5.1 升级到 7 后不起作用,但 CookieStore 可以
Redis as Session_Store Doesn't Work But CookieStore Does after upgrading from Rails 5.1 to 7
问:
将 rails 从 5.1 升级到 7 后,Redis for session_store 不再工作,即使我已经更新了我能找到的所有可能的东西。Redis 版本 = 7.2.3
更新了 Gemfile 以删除 redis-rails 并包含 redis-actionpack,因为它打包在 >= Rails5.2 中:
gem 'redis', '~> 5.0'
gem 'redis-actionpack', "~> 5.3"
在我的config/initializers/session_store.rb中
Rails.application.config.session_store :redis_store,
servers: ['redis://localhost:6379/0/session'],
key: '_repubclub_session_development',
expire_after: 1.days,
signed: true,
secure: false
当我运行时:我看到页面请求通过输出到达 Redis,如下所示:redis-cli monitor
1700062813.721011 [0 127.0.0.1:56195] "get" "2::a8fa0f1717f3b52bc7eb07bf006a569c3b9b2df87d70c93c5b2e500eea8ee53d"
1700062813.721201 [0 127.0.0.1:56195] "get" "dAmCGwLx3ebmdgLw96uWZnWO1agkR7DVtG1BzI5G8BxKoKEqmKuq+ZFzXIHL6w6dw2iERbwstVnmvrxVpDKcSEXmrDxZJs4u3zefOxz3/tr0uhtkUJlgLTtLHVEVveOo2XGfnoogMz1LkwOnKlinF4zVgRpGxqPZa3s5mxbwAQVQAQpnGqd8EHc5uYh6v0I3Evf2qXe0Dgw=--RTUjmnuEhMUDjlaz--ANyGuVkg015jrcKfYrwBNw=="
1700062813.768143 [0 127.0.0.1:56195] "setex" "2::ff56f6c452380a5887983d14c24c5d9673483a68e7ff1ee0945227e22fce9a03" "86400" "\x04\b{\aI\"\x0blocale\x06:\x06EF\"\aenI\"\x10_csrf_token\x06;\x00FI\"0-9bP3MWCLQfS_uX1BrCpQ9cDiyzEpTaRfz_uTSi7zpg\x06;\x00F"
然而,没有显示 flash 消息,任何 put/post 请求都会导致“ActionController::InvalidAuthenticityToken: Can't verify CSRF token authenticity”错误,如下所示:
Started POST "/sessions" for ::1 at 2023-11-15 11:22:46 -0500
ActiveRecord::SchemaMigration Load (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by SessionsController#create as HTML
Parameters: {"authenticity_token"=>"[FILTERED]", "session"=>{"cellphone"=>"", "password"=>"[FILTERED]"}}
Can't verify CSRF token authenticity.
Completed 500 Internal Server Error in 8ms (ActiveRecord: 0.0ms | Allocations: 3845)
当我换回使用 Rails 的 cookie_store 时,它又起作用了,我收到了适当的 flash 消息和身份验证。
答: 暂无答案
评论