通过passport设置github关联登录,一切正常,数据库中也写入了github用户名和邮箱,但是session中没有正确识别user信息。 在主页中有设置: {% if !currentUser %}
<li><a href="/login" class="btn btn-primary pull-right">登陆</a></li>
<li><a href="/register" class="btn btn-primary pull-right">注册</a></li>
{% else %}
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="" class="dropdown-toggle" data-toggle="dropdown">个人中心 <span class="glyphicon glyphicon-user pull-right"></span></a>
<ul class="dropdown-menu">
<li><a href="/profile">个人主页 <span class="glyphicon glyphicon-home pull-right"></span></a></li>
<li class="divider"></li>
<li><a href="/logout">退出登录 <span class="glyphicon glyphicon-log-out pull-right"></span></a></li>
</ul>
</li>
</ul>
{% endif %}
这个currentUser在app.js是这样存储的: app.use(function (req,res,next) { res.locals.currentUser=req.session.userId; //flash res.locals.success = req.flash(‘success’).toString(); res.locals.error = req.flash(‘error’).toString(); next(); });
passport-session也已经设置了 //Initialize Passport.js app.use(passport.initialize());
//Restore session app.use(passport.session()); 如何将github登录的用户名关联到currentUser呢?