Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

If statement considers FALSE promise as TRUE

I’m making authentication in my app.
And have such code

  const ttt = currentUser.changedPasswordAfter(decoded.iat);
  console.log(ttt);
  if (ttt) {
    console.log('if thinks ttt is true');

changedPasswordAfter retuns promise (true or false)
So I run request and get this into console.

Promise { false }
if thinks ttt is true

As you see ttt is FALSE but IF statement decided that it is TRUE .
How can I fix that ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because ttt (which is a very bad name for a variable) is a Promise not a boolean so the if statement return True because the variable ttt has reference (is not undefined or null).
try to add await keyword. it will work but you have to make the function Async

const ttt = await currentUser.changedPasswordAfter(decoded.iat);
  console.log(ttt);
  if (ttt) {
    console.log('if thinks ttt is true');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading