0

I have a mongoose custom service which will check if token exist from db and I wanted it to return boolean however in my controller I got a promise.

token.services.js

async tokenExists(token) {
 const foundToken = await TokenModel.findOne({'token': token})

 if (foundToken) {
   return true;
 }

  return false;
}

Controller.js

 const tokenExists= this.tokenService.tokenExists(token);

 console.log('tokenExists', tokenExists);

However I got a promise instead of boolean see below. Console Output

 tokenExists Promise { <pending> }

Did I do something wrong? or is there a way for it to it?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
blitzen12
  • 1,350
  • 3
  • 24
  • 33

0 Answers0