所以我正在开发我的ionic4应用程序,在sendEmailVerification函数上出现错误。控制台问我是否忘记使用"等待"。解决方案是什么?谢谢
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
@Injectable({
providedIn: 'root'
})
export class FirebaseAuthService {
constructor(private angularFireAuth: AngularFireAuth) { }
async registerWithEmailPassword(email, password) {
try {
const result = await this.angularFireAuth.createUserWithEmailAndPassword(email, password);
await this.angularFireAuth.currentUser.sendEmailVerification();
return result;
}catch (error) {
throw new Error(error);
}
}
}
似乎currentUser
是一个承诺,因此解决方案可能是:
...
await (await this.angularFireAuth.currentUser).sendEmailVerification();
...
请注意,只有当sendEmailVerification
返回promise并且您需要等待它完成后才能返回结果时,才需要外部await
。