Sinatra not persisting session with redirect on Chrome

核能气质少年 提交于 2019-12-03 11:55:21

Add this to your main app file: use Rack::Session::Cookie, :key => 'rack.session', :path => '/', :secret => 'some-random-string'

With that added, you should be able to assign session['whatever'] and have it work as expected.

Please try to disable all custom cookie managament extensions is Chrome if any. After that check headers in Developer toolsNetwork. Should see 'Cookie:' field.

Xero Essential

I think that just because you didn't set :session_secret, refer to my answer on here

By doing enable :sessions you just get access to session per request. Sinatra has no way to keep the reference to the previous call (your redirect) as it is treated as another request.

Thus, long story short:

set :session_secret, "SecureRandom.new(10) generated thing" enable :sessions

always use enable :sessions with a secret, otherwise your session is recreated every time rack sees a request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!