As you can see in the NodeJS code I'm grabbing the user from the token from Postman provided in the URL but I'm struggling to get back the _id property from the given token number. What I want is that id in the decoded._id so that I can use that id in further operations
const jwt = require('jsonwebtoken')
const User = require('../model/users')
const auth = async (req, res, next) => {
try {
const token = req.header('Authorization').replace('Bearer', '')
const decoded = jwt.verify(token, 'thisisfromabhishek')
`the property _id does not exist on decoded`
const user = await User.findOne({ _id: decoded._id, 'tokens.token': token })
if (!user) {
throw new Error()
}
req.token = token
req.user = user
next()
} catch (e) {
res.status(401).send({ error: 'Please authenticate.' })
}
}
module.exports = auth