Rails ActiveRecord store and new session

后端 未结 3 441
轻奢々
轻奢々 2021-01-12 05:49

I am new to Rails and experience a strange issue I don\'t understand. I use ActiveRecord as a session store and need to add session id as a property of JSON responses for al

3条回答
  •  醉梦人生
    2021-01-12 06:15

    The problem I experienced was caused by default Warden configuration. It renewed session id, but somehow the new id was not accessible via session.id.

    The only way I found to stop this behavior was putting this code into config/initializers/devise.rb:

    Warden::Manager.after_set_user do |user,auth,opts|
      auth.env["rack.session.options"][:renew] = false
    end
    

    Probably this method is not really good for security reasons, but I have no other ideas in a week of searching and reading sources.

提交回复
热议问题