在Express中的视图中访问会话变量

时间:2019-02-03 19:26:07

标签: node.js express

我正在使用用户注册和登录功能构建一个简单的网页

尝试访问变量console.log(session.email);会导致undefined

app.use(function (req, res, next) {
    res.locals.isAuthenticated = req.isAuthenticated();
     var session = req.session;
    console.log(session); 
    console.log(session.email); 

    // res.locals.user_id = req.session.id;

    next();
});

当我console.log(session)时,结果如下:

Session {
    cookie:
   { path: '/',
     _expires: 2019-02-03T20:58:32.951Z,
     originalMaxAge: 6000000,
     httpOnly: false,
     secure: false },
  messages: [ 'Welcome Back' ],
  passport:
   { user:
      { id: 1,
        name: 'test',
        email: 'test@test.com',
        country: 'Europe',
        gender: 'Male',
        accountcreation: '2019-02-01T16:14:56.000Z',
        accountlastlogin: '',
        accountemailstatus: 0 } } }

0 个答案:

没有答案