如何将userid连接到loggedin用户

xbp102n0  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(206)
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的正确方法是什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题