Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

How to make a function not work if another function was called

$
0
0

@kingeke wrote:

I have angularfireauth in my code…

when the user logs in and assuming he closed the app or something, when the app opens back up it checks if there’s a user logged in with:

this.afAuth.auth.onAuthStateChanged(user => {
if (user) {
if (user.emailVerified) {
this.presentToast(‘Please wait’, ‘middle’);
this.afDatabase.object(users/${user.uid}).snapshotChanges().map(
action => {
const data = action.payload.toJSON();
return data;
}
).subscribe(
result => {
this.toast.dismiss();
this.events.publish(‘user:loggedIn’, result);
this.navCtrl.setRoot(DashboardPage, result);
}
);
}
}
});

but then assuming there’s no user logged in and a user wants to log in using the login function:

loginUser(email: string, password: string) {
this.normalLoader();
this.afAuth.auth.signInWithEmailAndPassword(email, password).then(
user => {
if (user.emailVerified) {
setTimeout(() => {
this.loading.dismiss();
this.afDatabase.object(users/${user.uid}).snapshotChanges().map(
action => {
const data = action.payload.toJSON();
return data;
}
).subscribe(
result => {
this.events.publish(‘user:loggedIn’, result);
this.navCtrl.setRoot(DashboardPage, result);
}
);
}, 3000)
}
else {
this.showAlert(‘Email Not Verified’, ‘You have not verified your email, we have sent another verification mail to you!’);
this.sendEmailVerification();
this.loading.dismiss();
}
}
).catch(
errors => {
setTimeout(() => {
this.loading.dismiss(),
this.showAlert(‘Error’, errors.message);
}, 3000)
}
);
}

the presentToast fires up because the authState has changed… how can i prevent this ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>