bjwhip
bjwhip

Reputation: 467

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. After Firebase updated to version 4.13.1, I updated Angular to 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

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. Why did it break and how would I build a reset password button with Firebase 4.13.1?

Upvotes: 1

Views: 2306

Answers (2)

ForrestLyman
ForrestLyman

Reputation: 1652

you also need to import the auth package if you are using the Firebase SDK in typescript:

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

Upvotes: 0

Isurendrasingh
Isurendrasingh

Reputation: 432

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))

Upvotes: 1

Related Questions