Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'authState' does not exist on type 'AngularFireAuth' in ionic 2 app

I am trying to do facebook authentication using firebase's AngularFire2. I am following the exact same steps as this Tutorial github.com/angular/angularfire2/blob/master/docs/Auth-with-Ionic2.md

But for some reason, this doesn't work. It gives me, many errors from my provider's page. Here is my code.

import { Injectable } from '@angular/core';
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';


@Injectable()
export class AuthService {
     private authState: Observable<firebase.User>;
     private currentUser: firebase.User;

     constructor(public http: Http, public afAuth: AngularFireAuth) {
     console.log('Hello AuthService Provider');
     this.authState = afAuth.authState; //First error here.
     afAuth.subscribe((user: firebase.User) => { //second here
     this.currentUser = user;
      });
}

  get authenticated(): boolean {
    return this.currentUser !== null;
  }

  signInWithFacebook(): firebase.Promise<any> {
     return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()); //third error here
      }

  signOut(): void {
    this.afAuth.signOut();
  }

  displayName(): string {
    if (this.currentUser !== null) {
      return this.currentUser.facebook.displayName;
       } else {
       return '';
       }
   }
}

Errors

Property 'authState' does not exist on type 'AngularFireAuth'.

Argument of type '(user: User) => void' is not assignable to parameter of type '(value: FirebaseAuthState) => void'. 
Types of parameters 'user' and 'value' are incompatible. 
Type 'FirebaseAuthState' is not assignable to type 'User'. 
Property 'delete' is missing in type 'FirebaseAuthState'.

Property 'auth' does not exist on type 'AngularFireAuth'.

I am pretty new to angular and ionic, please guide me here, or navigate me to a good tutorial

like image 507
Mayur Tolani Avatar asked May 07 '17 21:05

Mayur Tolani


2 Answers

I solve this problem re-installing Firebase and AngularFire2:

npm uninstall angularfire2 --save
npm uninstall firebase --save
npm install angularfire2 firebase --save

Update:

npm install firebase @angular/fire --save
like image 153
Alexis Gamarra Avatar answered Nov 13 '22 18:11

Alexis Gamarra


The corrected answer last line is now deprecated

npm install firebase @angular/fire --save

like image 32
AbdulAzeez Olanrewaju Avatar answered Nov 13 '22 18:11

AbdulAzeez Olanrewaju