So i have the following:
signToken(payload) {
return new Promise(function(resolve, reject) {
if( ! payload ) {
return reject('Payload not specified.');
}
jwt.sign(payload, secret, function(err, token) {
if( err ) {
return reject('Token not signed ' + err);
}
return resolve(token);
});
});
}
app.post('/', function(req, res) {
clientToken.signToken(req.body.text).then(function(token) {
res.cookie('cl_a', response, { domain: 'localhost', maxAge: 9000000, httpOnly: true});
res.json({ message: 'Successfully Authenticated' });
res.status(200).end();
console.log('1');
}).catch(function(err) {
res.json({ message: 'Something Went Wrong' });
res.status(403).end();
});
});
When posting on "/" with the payload the promise gets resolved but instead of executing ".then" the ".catch" part is running.
Can somebody help with a better example :D ?
via Bogdan Crișu
No comments:
Post a Comment