I’m making authentication in my app. And have such code
JavaScript
x
5
1
const ttt = currentUser.changedPasswordAfter(decoded.iat);
2
console.log(ttt);
3
if (ttt) {
4
console.log('if thinks ttt is true');
5
changedPasswordAfter retuns promise (true or false) So I run request and get this into console.
JavaScript
1
3
1
Promise { false }
2
if thinks ttt is true
3
As you see ttt is FALSE but IF statement decided that it is TRUE . How can I fix that ?
Advertisement
Answer
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
JavaScript
1
5
1
const ttt = await currentUser.changedPasswordAfter(decoded.iat);
2
console.log(ttt);
3
if (ttt) {
4
console.log('if thinks ttt is true');
5