filip
filip

Reputation: 45

Cannot read property 'split' of undefined in Nodejs

module.exports = {
  verifyToken(req, res, next){

    if(!req.headers.authorization){
      return res.status(401).send('Unauthorised request')
    }

    let token = req.headers.authorisation.split(' ')[1];

    if(token === null ){
      return res.status(401).send('Unauthorised request')
    }
    let payload = jwt.verfy(token, 'SECRETKEY')
    if(!payload){
      return res.status(401).send('Unauthorised request')
    }
    req.id = payload.subject
    next()
  }
}

i am trying to see if the user is authorized to access the mylist resource on frontend. does anyone have any idea?

Upvotes: 0

Views: 1483

Answers (1)

eol
eol

Reputation: 24565

Probably this is just a simple typo since you already check if the authorization-header exists. So change authorisation to:

let token = req.headers.authorization.split(' ')[1];

Upvotes: 1

Related Questions