Get the logged-in user id of a nodes.js session

Asked

Viewed 768 times

0

I am using the Passport with Session and need to get the user id of a session. I tried to use:

router.get('/', (req, res) =>{
    execSQLQuery('SELECT * FROM users WHERE id=' +  req.user.id, res);
})

Error:

Cannot read property 'id' of undefined
  • 1

    would not be req.params.id? from what I understand Oce is passing the id through the url parameter.

  • Actually I’d like to pick up by the session, I tried to do using the rarameter by the url but it’s not viable for application. But thank you for correcting the question.

1 answer

-1

If you want to get the id from the url is req.query.id But I use with Nosql, I do not know if it works with SQL. See if express has this possibility to use with SQL: https://expressjs.com/pt-br/api.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.