Reputation: 49
I am trying to display error messages to the user when they are signing up. I can't figure out why I keep getting the following errors on my code.
error TS1308: 'await' expression is only allowed within an async function.
Here is the code:
async signUp() {
firebase.auth().createUserWithEmailAndPassword(
this.realemail, this.realpassword
).then((user) => {
this.navCtrl.navigateForward("username-sign-up");
}).catch((err) => {
console.log(err);
const errmessage = await this.toastCtrl.create({
message: err.message,
duration: 3000
});
await errmessage.present();
})
}
Upvotes: 2
Views: 278
Reputation: 537
Try adding async to your catch handler. It's a method like any other, so in order to call async in, it needs to be async itself.
async signUp() {
firebase.auth().createUserWithEmailAndPassword(
this.realemail, this.realpassword
).then((user) => {
this.navCtrl.navigateForward("username-sign-up");
}).catch(async (err) => {
console.log(err);
const errmessage = await this.toastCtrl.create({
message: err.message,
duration: 3000
});
await errmessage.present();
})
}
Upvotes: 3