title: Else statement executes even if the If statement conditions are valid
body: <p>I am using Google Cloud function to validate my OTP Authentication, and also using Firebase database to save code in the database.</p>
  
  <p>My problem is, even when the If statements condition are satisfied, it always executes else statement. I am comparing code and codeValid from firebase database with the user input. Thus, my user input is satisfied with code and codevalid is also satisfied, but it always moves to else statement. I dont know why. </p>
  
  <p>Here is my code</p>
  
  <pre><code>const admin = require('firebase-admin');
  
  module.exports = function(req, res) {
  if(!req.body.phone || !req.body.code) {
      return res.status(422).send({error: 'Phone and Code Must be 
  Provided'});
   }
  
  const phone = String(req.body.phone).replace(/[^\d]/g, '');
  const code = parseInt(req.body.code);
  
  return admin.auth().getUser(phone) 
      .then(() =&gt; {
          const ref = admin.database().ref('users/'+ phone);
         return ref.on('value', snapshot =&gt; {
              ref.off();
              const user = snapshot.val();
  
              if (user.code === code &amp;&amp; user.codeValid === true) {
                  ref.update({ codeValid: false });
                  admin.auth().createCustomToken(phone)
                      .then(token =&gt; res.send({ token: token }))
                      .catch((err)=&gt; res.status(422).send({ error:err }));
              }
              else {
                  return res.status(422).send({ error: 'Code Not Valid' });
              }
          });
      })
      .catch((err)=&gt; res.status(422).send({ error:err }) )
   } 
  </code></pre>
  
  <p>So, I always get "code not valid" what ever the input i give. I cross checked all the values with firebase database also, everything matches. But couldn't find why its happening.</p>