May*_*ani 6 angularjs firebase firebase-authentication ionic2 angularfire2
我正在尝试使用 firebase 的 AngularFire2 进行 Facebook 身份验证。我遵循与本教程完全相同的步骤github.com/angular/angularfire2/blob/master/docs/Auth-with-Ionic2.md
但由于某种原因,这行不通。它给了我提供者页面上的许多错误。这是我的代码。
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 '';
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误
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'.
Run Code Online (Sandbox Code Playgroud)
Property 'auth' does not exist on type 'AngularFireAuth'.
我对 angular 和 ionic 还很陌生,请在这里指导我,或导航到一个好的教程
我重新安装 Firebase 和 AngularFire2 解决了这个问题:
npm uninstall angularfire2 --save
npm uninstall firebase --save
npm install angularfire2 firebase --save
Run Code Online (Sandbox Code Playgroud)
更新:
npm install firebase @angular/fire --save
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2999 次 |
| 最近记录: |