RxDev
RxDev

Reputation: 295

Angularfire2 error TS2304: Cannot find name 'firebase'

My authentification service is throwing this error when I try to serve it

error TS2304: Cannot find name 'firebase'.

It also occurs when I try to build it in production mode throwing this error message:

error TS2339: Property 'firebase' does not exist on type '{ production: boolean; }'.

I am using "angularfire2": "^5.0.0-rc.6" and "firebase": "4.10.1"

and this is my authentification service :

import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from '@firebase/app';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';
import {MatSnackBar} from '@angular/material';

@Injectable()
export class AuthentificationService {
  user: Observable<firebase>;

  constructor(private firebaseAuth: AngularFireAuth, private router: Router,
    public snackBar: MatSnackBar) {
    // authentification initialisation
    this.user = firebaseAuth.authState;
  }

  // login
  login(email: string, password: string) {
    this.firebaseAuth
      .auth
      .signInWithEmailAndPassword(email, password)
      .then(value => {
        console.log('Nice, it worked!');
        this.snackBar.open('Connection réussie', 'OK', {
          duration : 500
        });
        this.router.navigate(['/dataP']);
      })
      .catch(err => {
        console.log('Something went wrong:', err.message);
        this.snackBar.open('Echec de la connection', 'OK', {
          duration : 500
        });
      });
  }

  // logout
  logout() {
    this.firebaseAuth
      .auth
      .signOut();
  }

}

Any idea on how to solve this?

Upvotes: 0

Views: 841

Answers (1)

RxDev
RxDev

Reputation: 295

I figured out how to solve this probleme I just change user: Observable<firebase>; to user: Observable<firebase.User>; and I have no error anymore

Upvotes: 1

Related Questions