问题描述
所以我正在使用ionic4应用程序,但在try-catch块中的 auth 上出现错误。我尝试安装firebase软件包并添加 auth 导入,但似乎没有任何效果。可能是什么问题?
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Auth } from 'firebase';
@Injectable({
providedIn: 'root'
})
export class FirebaseAuthService {
auth: any[];
constructor(private angularFireAuth: AngularFireAuth) { }
async registerWithEmailPassword(email,password) {
try {
const result = await this.angularFireAuth.auth.createUserWithEmailAndPassword(email,password);
await this.angularFireAuth.auth.currentUser.sendEmailVerification();
return result;
} catch (error) {
throw new Error(error);
}
}
}
解决方法
使用最新的AngularFireAuth,您不再需要指定.auth。
您可以直接访问angularFireAuth.currentUser以获取用户信息。