简体   繁体   English

更新 Firebase 和 Angular 后获取“firebase.auth is not a function”

[英]Getting “firebase.auth is not a function” after updating Firebase and Angular

I recently built a web app using Angular 5 and Firebase using an email password authentication.我最近使用 Angular 5 和 Firebase 使用电子邮件密码身份验证构建了一个网络应用程序。 After Firebase updated to version 4.13.1, I updated Angular to 5.2.9. Firebase 更新到 4.13.1 版本后,我将 Angular 更新到 5.2.9。 Now my password reset doesn't work.现在我的密码重置不起作用。

auth.Service:身份验证服务:

import * as firebase from 'firebase';

resetPassword(email: string) {
    const fbAuth = firebase.auth();

    return fbAuth.sendPasswordResetEmail(email)
      .then(() => console.log('sent Password Reset Email!'))
      .catch((error) => console.log(error))
}

Component:成分:

resetPassword(email) {
  this.authService.resetPassword(email)
  .then(() => this.passReset = true)
}

In the console I get the error:在控制台中,我收到错误消息:

TypeError: firebase.auth is not a function at AuthService.resetPassword类型错误:firebase.auth 不是 AuthService.resetPassword 的函数

I can't find any code that doesn't include "firebase.auth" or any reason to why the recent update may have taken away the function I was using.我找不到任何不包含“firebase.auth”的代码或任何最近更新可能会取消我正在使用的功能的原因。 Why did it break and how would I build a reset password button with Firebase 4.13.1?为什么它会损坏,我将如何使用 Firebase 4.13.1 构建重置密码按钮?

You need to change these line您需要更改这些行

return this.afAuth.auth.sendPasswordResetEmail(email)
  .then(() => console.log('sent Password Reset Email!'))
  .catch((error) => console.log(error))

to the following lines到以下几行

return fbAuth.sendPasswordResetEmail(email)
  .then(() => console.log('sent Password Reset Email!'))
  .catch((error) => console.log(error))

you also need to import the auth package if you are using the Firebase SDK in typescript:如果您在打字稿中使用 Firebase SDK,您还需要导入 auth 包:

import * as firebase from 'firebase/app';
import 'firebase/auth';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM