节点Js – 会话pipe理

我有一个简单的应用程序,它将login一个用户,并根据他的angular色将让他使用一个特定的API(比如normal / admin..view / update分别)。 我正在使用MYSQL来validation用户和连接池来pipe理许多应用程序的连接。

这是我如何pipe理会议,

app.use(expressSession({ cookieName: 'session', secret: 'mysecret', duration: 15 * 60 * 1000, })); 

login时,

 app.post('/login',function(req,res){ Authenticate(req.body.username,req.body.password,function(err,fname,user){ if(!err) { req.session.name=user; res.send("Welcome " + fname); } else{ res.send("There seems to be an issue with the username/password combination that you entered"); } }); }); 

每当我想访问任何特定的API,我会检查这个会话名称。

 app.post('/updateInfo',function(req,res){ if(req.session.name){ // My logic - i ll return the role by searching in db using this req.session.name, if admin will allow him. } }); 

我将在注销中销毁会话。

我有两个问题,因为我不明白节点js中的会话机制。

  1. 现在假设我以pipe理员用户身份login,并在authentication后导出cookie(比如说使用编辑这个cookie chrome扩展名)并注销。 然后以普通用户身份login并导入cookie(admin cookie),是否会有违规行为(因为现在会话将包含pipe理员用户名)?
  2. 假设如果我想避免同一用户(用户使用不同的浏览器/手机login)的多个连接,我可以只添加这段代码?

     if(req.session.name == req.body.username) { req.session.destroy(); } 

然后继续authentication? 这里有什么缺点? 为什么它会工作或不工作?

我真的很想做这个无状态(不想坚持状态/会话在分贝),因为我想performance。 我可以做一些无国籍的东西,即使有100个并发用户,也可以工作吗?