router.get('/profilePage/:userid', function(req, res) {
var userid = req.session.user
console.log(userid)
if (!userid) {
//No user id provided
} else {
pool.query('SELECT * from users where id = ?',
[userid],
(error, results, feilds)=> {
if (error) {
console.log("error ocurred while getting user details of " + userid, error);
res.send({
"code": 400,
"failed": "error ocurred"
});
} else {
if (results.length > 0) {
const profile = results[0]
//You can then access the user id with
console.log(profile.fullname)
res.render("profilePage",{profile});
} else {
console.log('unable to retrieve a profile')
}
}
});
}
});
如何使userid=登录用户?我尝试了很多方法,比如sessions(var userid=req.session.user),但都不起作用。让userid=登录用户id的正确方法是什么?
暂无答案!
目前还没有任何答案,快来回答吧!