samedi 26 septembre 2015

Node.JS variable outside function

I am using mongodb and mongoose in node.js Inside the function, it verifies the username and password. user.password works inside the first if statement, but after that in the if else below, where the user actually comes into play it returns.

              if (password1 == user.password) {
                                   ^
TypeError: Cannot read property 'password' of null

The code that I have is.

User.findOne({ 'Username: ': username1}, function(err, user) {
    if (err){
        console.log("There was an error proccesing the request".red + " : ".red + err);
    } else if (user == '') {
        console.log("This user was not found")

    } else {
      prompt('Password: ', function(password1){
          if (password1 == user.password) {

              console.log("User Login Sucsess")
          } else {

              console.log("Password incorrect")
              proccess.exit();
          }


          console.log("made it");


      })

    }
})

Anyone know how to fix this issue

Thank you!

Aucun commentaire:

Enregistrer un commentaire