...
|
...
|
@@ -7,8 +7,13 @@ module.exports = () => { |
|
|
return (req, res, next) => {
|
|
|
// 从 SESSION 中获取到当前登录用户的 UID
|
|
|
if (req.session && _.isNumber(req.session.LOGIN_UID)) {
|
|
|
req.user.uid = req.session.LOGIN_UID;
|
|
|
|
|
|
// 不要使用 === 判断uid的值,如果需要判断使用 ==
|
|
|
req.user.uid = {
|
|
|
toString: () => {
|
|
|
return req.session.LOGIN_UID;
|
|
|
},
|
|
|
sessionId: req.cookies._session
|
|
|
};
|
|
|
let userData = _.get(req.session, 'USER', {});
|
|
|
|
|
|
_.merge(req.user, userData);
|
...
|
...
|
@@ -16,7 +21,13 @@ module.exports = () => { |
|
|
|
|
|
// session 没有读取到的时候,从 cookie 读取 UID
|
|
|
if (!req.user.uid && req.cookies._UID) {
|
|
|
req.user.uid = cookie.getUid(req);
|
|
|
// 不要使用 === 判断uid的值,如果需要判断使用 ==
|
|
|
req.user.uid = {
|
|
|
toString: () => {
|
|
|
return cookie.getUid(req);
|
|
|
},
|
|
|
sessionId: req.cookies._session
|
|
|
};
|
|
|
}
|
|
|
|
|
|
next();
|
...
|
...
|
|