Sinatra 会话会自动销毁
我不知道为什么,但我的会话被清除了每个请求。
这是我的代码
require 'rubygems'
require 'sinatra'
require 'sinatra/base'
require 'haml'
require 'facebook_oauth'
class MyClass < Sinatra::Base
set :logging, true
set :sessions, true
get "/auth/facebook_callback" do
// Do some facebook login which is fine
access_token = facebookClient.authorize(:code => params[:code])
session[:access_token] = access_token.token
session[:user] = facebookClient.me.info['name']
session[:id] = facebookClient.me.info["id"]
#print session by "pp session" I can still see all the sessions
redirect '/'
end
get '/' do
#print all the sessions again. And I can't see anything. The session_id is also different
end
end
I'm not sure why but my session gets wiped out every request.
This is my code
require 'rubygems'
require 'sinatra'
require 'sinatra/base'
require 'haml'
require 'facebook_oauth'
class MyClass < Sinatra::Base
set :logging, true
set :sessions, true
get "/auth/facebook_callback" do
// Do some facebook login which is fine
access_token = facebookClient.authorize(:code => params[:code])
session[:access_token] = access_token.token
session[:user] = facebookClient.me.info['name']
session[:id] = facebookClient.me.info["id"]
#print session by "pp session" I can still see all the sessions
redirect '/'
end
get '/' do
#print all the sessions again. And I can't see anything. The session_id is also different
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了保持会话一致,您需要设置一个会话密钥,例如:
如果未设置会话密钥,sinatra 会在应用程序启动时生成随机密钥,并且 shotgun 在每个请求之前都会重新启动应用程序。
To keep sessions consistent you need to set a session secret, e.g.:
When it's not set sinatra generates random one on application start and shotgun restarts application before every request.