unable to read data from decoded token jwt verify

178 views Asked by At
jwt.verify(token,process.env.SECRETKEY, function(err,decodedToken){

      console.log(decodedToken);

    })
Console output
{ email: '[email protected]', iat: 1601341321 }

how can I read the value of email from decoded token?

1

There are 1 answers

0
Juan Rambal On

Attach the email to the request, then you can access that value from the controller

jwt.verify(token,process.env.SECRETKEY, function(err,decodedToken){
      if(err) throw new ForbiddenException('Invalid token'); 
      req.user = decodedToken //Attach token payload to request
    })

You can use that value later on the controller using req.user or creating a decorator (I prefer this).