简体   繁体   English

使用Angular4和Angularfire2(v4)在Firebase中获取用户身份验证配置文件信息

[英]Get User Auth Profile Info in Firebase using Angular4 and Angularfire2 (v4)

Looking at this solution (angular2), I have been trying to get the same functionality to work in angular4 and coming up short. 看着这个解决方案 (angular2),我一直在尝试让相同的功能在angular4中工作,并且很快。 The error I get is: 我得到的错误是:

Property 'subscribe' does not exist on type 'Auth' 类型“ Auth”上不存在属性“ subscribe”

Here is some sample code (not working): 这是一些示例代码(不起作用):

angularFire.ts (provider): angularFire.ts(提供者):

import {Injectable} from "@angular/core";
import { Observable } from 'rxjs/Observable';
import { FirebaseObjectFactoryOpts } from "angularfire2/interfaces";
import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';

@Injectable()
export class AF {
  public messages: FirebaseListObservable<any>;
  public users: FirebaseListObservable<any>;
  public displayName: string;
  public email: string;
  public user: Observable<firebase.User>;

  constructor(private afAuth: AngularFireAuth, private db: AngularFireDatabase) {
    this.afAuth.auth.subscribe(
      (auth) => {
        if (auth != null) {
          this.user = db.list.object('users/' + auth.uid);
        }
      });
    this.messages = db.list('messages');
    this.users = db.list('users');
  } ... 
}

使用AngularFire2,您必须订阅authState ,而不是auth

this.afAuth.authState.subscribe()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM