【问题标题】:error TS2339: Property 'auth' does not exist on type 'AngularFireAuth'错误 TS2339:“AngularFireAuth”类型上不存在属性“auth”
【发布时间】:2020-11-30 12:09:17
【问题描述】:

所以我正在开发我的 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);
    }
  }
}

【问题讨论】:

    标签: angular typescript ionic-framework firebase-authentication angularfire2


    【解决方案1】:

    使用最新的 AngularFireAuth,您无需再指定 .auth。

    可以直接访问angularFireAuth.currentUser获取用户信息。

    【讨论】:

    • 感谢您,我已经删除了两行代码的 .auth 规范,但现在我被提示在 'sendEmailVerification() '方法上使用 'await'。我能做什么?
    • 试试这个:this.angularFireAuth.currentUser.then(u => u.sendEmailVerification()) .then(() => { this.router.navigate(['verify-email']) ; });
    猜你喜欢
    • 1970-01-01
    • 2019-01-21
    • 2016-08-13
    • 2017-12-20
    • 2016-11-14
    • 2017-10-24
    • 2021-08-10
    • 2018-11-17
    • 2020-09-25
    相关资源
    最近更新 更多