Property 'GoogleAuthProvider' does not exist on type 'AngularFireAuth'.ts(2339)

Viewed 78

I am using 'AngularFireAuth' for sign in with Google and I am getting tis error.

Ths is my code written in auth.service.ts:

import { Injectable } from '@angular/core';
import { first } from 'rxjs/operators';
import { AngularFireAuth } from '@angular/fire/compat/auth';

@Injectable({
  providedIn: 'root'
})
export class AuthService {

  constructor(public afauth: AngularFireAuth) { }

  googleSignIn() {
    const provider = new this.afauth.GoogleAuthProvider();
    return this.oAuthLogin(provider);
  }

  async getUser() {
    return this.afauth.authState.pipe(first()).toPromise();
  }
}
1 Answers

GoogleAuthProvider needs to be imported from firebase/auth

here is the code for your login (credits goes to positronx)

import { Injectable } from '@angular/core';
import { GoogleAuthProvider } from 'firebase/auth';
import { AngularFireAuth } from '@angular/fire/compat/auth';
@Injectable({
  providedIn: 'root',
})
export class AuthService {
  constructor(
    public afAuth: AngularFireAuth // Inject Firebase auth service
  ) {}
  // Sign in with Google
  googleSignIn() {
    return this.AuthLogin(new GoogleAuthProvider());
  }
  // Auth logic to run auth providers
  AuthLogin(provider) {
    return this.afAuth
      .signInWithPopup(provider)
      .then((result) => {
        console.log('You have been successfully logged in!');
      })
      .catch((error) => {
        console.log(error);
      });
  }
}
Related