Session node.JS-express framework创建会话并检查会话是否存在

Session node.JS-express framework创建会话并检查会话是否存在,session,node.js,express,Session,Node.js,Express,这是我的服务器代码,请看代码中的注释 var app = express.createServer(); app.get('/', function(req, res){ // create a session with the value of an email for example: me@gmail.com }); // down here I want to check the session if the session exist if( there is a sessi

这是我的服务器代码,请看代码中的注释

var app = express.createServer();
app.get('/', function(req, res){
    // create a session with the value of an email for example: me@gmail.com
});

// down here I want to check the session if the session exist
if( there is a session with value me@gmail.com){
    //do stuff  
}

Connect/Express中会话的实现方式不允许自定义会话ID。这部分是因为安全性。所以你可以做很多事情

  • 存储会话中的所有内容。在某处(可能在数据库中)创建一个索引,将电子邮件地址映射到会话ID,以便您可以通过电子邮件查找会话

  • 在会话中仅存储电子邮件。将实际会话数据保存在其他地方(可能在数据库中),您可以通过电子邮件地址获取它

  • 创建您自己的会话中间件,可能基于Connect的代码。Connect中的实际会话代码只有300行。但是要非常小心地保持安全功能完好无损