Newbie mobile developer here. I'm trying to implement User Logins with Backendless but I don't know whats the best way to do it, especially to avoid making too many API calls.
I know there are several malpractices (especially UX) here but I'm really just trying to get the logic right first.
In the following excerpt, I try making a log-in and when it's done give the user access to the app. If its not successful Id like the alert to be made. However, the app shows the alert independently of the credentials being correct. It's like the if starts executing before the login has been completed.
I'm not looking for a workaround, I'm a noob developer and honestly, don't know the best way to handle this. I would be very appreciative of help. Thanks, guys!
Backendless.userService.login(email, password).then((user) => boologin=true);
if (boologin==true) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Home(),
),
);
} else {
showBasicAlert(context,
"Wrong username or password", "");
boologin
is always false
when it reaches to if
. Because login
is asynchronous and before boologin = true
being set, code flow continues. Try to change it like here
await Backendless.userService.login(email, password);
Then to set boologin = true