1
I have the following login function:
function login(username, password, callback) {
var myResponse;
var systemUser;
Users.getByLogin(username)
.then(function (response) {
systemUser = response.data;
});
// Linha testada
console.log("Senha: " + systemUser.password);
console.log("Senha informada: " + password);
if (typeof systemUser == "undefined") {
myResponse = { success: false, message: "Usuário inexistente!" };
} else if (password == systemUser.password) {
myResponse = { success: true, user: systemUser };
} else {
myResponse = { success: false, message: "Usuário ou senha incorretos!" };
}
callback(myResponse);
}
Usually the error occurs TypeError: Cannot read property 'password' of undefined
.
If I declare the variable systemUser
out of function , noting the line of the comment Linha testada
, the value gives Undefined the first time I call the method, but the second time passes.
I forgot even this synchronization issue, really AJAX queries are asynchronous! Thank you!
– Shura16