I have so far succeeded in acquiring a jwt token passed from front-end - angular to nodejs server. However, I get the error -
UnauthorizedError: invalid signature
can you please point out what is wrong with my syntax/code ?
app.component.ts
var token = localStorage.getItem('token')
return new Promise((resolve, reject) => {
var headers= new HttpHeaders({'Authorization': 'Bearer ' + token});
this.http.get(this.nodejsUrl + "getMongoDData/getSystem" +emptyObj, { headers:headers })
server.js
var cors = require('cors');
var expressJwt = require('express-jwt');
var session = require('express-session');
app.use(cors({
'Access-Control-Allow-Headers' : 'Content-Type, Authorization'
}));
app.use(expressJwt({
secret: config.secret,
credentialsRequired: false,
getToken: function (req) {
if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
return req.headers.authorization.split(' ')[1];
} else if (req.query && req.query.token) {
return req.query.token;
}
return null;
}
})
.unless({
path: ['/forgotP/forgotPassword', '/login/authenticate',
]
})
);