I am having an issue where the getAuthToken functions is not returning the data from the database based off the filter. Instead, it just return an empty object which causes the next api to fail. Am I missing something? the other functions work fine, it's just the get. Let me know if you need any more information. Thanks in advance for the help.
The api controller I am calling is:
function getAllCategoriesWithImages(req, res, next) {
const payload = jwtDecode(req.headers.authorization.split(' ')[1]);
authService.getAuthToken(payload.sub.toString())
.then(token => cloverService.getAllCategoriesWithImages(req.body, token.merchantId, token.cloverToken))
.then(users => res.send(users))
.catch(err => next(err));
}
and my getAuthToken function is:
async function getAuthToken(userId)
{
console.log('userud ' +userId);
const existingCredentials = await authentication.findOne({ userId: userId});
console.log('token ' +JSON.stringify(existingCredentials));
return existingCredentials;
}
the console log in the getAuthToken() logs:
here {}