I need assistance with waiting for a promise to return within a method.
public async loginOffline(username: string, password: string) {
const data = await this.database.getItem('currentUser', 'login');
this.userLogin = data;
console.log(`${username} ${this.userLogin.username} ${password} ${this.userLogin.password}`);
if (username === this.userLogin.username && password === this.userLogin.password) {
return true;
} else {
return false;
}
}
/********* Calling the method and deciding what to do **************/
if (await loginOffline('myname', 'mypassword')) {
// Do something.....
} else {
// Do something else .....
}
......
The current implementation is not functioning as expected. The caller of the loginOffline
method only needs confirmation on whether the login was successful. I have attempted multiple approaches but none have worked so far.
If anyone can provide some guidance, it would be greatly appreciated. Thank you very much.