物业' currentUser'类型' FirebaseAuthState'中不存在

时间:2016-08-24 01:55:05

标签: angular firebase firebase-authentication angularfire2

尝试在angularfire2中获取currentUser。什么类型暴露了这个?

https://firebase.google.com/docs/reference/js/firebase.auth.Auth

对于我来说,探索这个观察结果并不明显:

constructor(private auth: FirebaseAuth) {
  auth.subscribe((user) => console.log('user is', user));    
}

1 个答案:

答案 0 :(得分:0)

我从user observable收到的FirebaseAuth对象包含以下属性:

  • provider
  • uid
  • auth

最后一个 - auth - 是currentUser。如果您查看source,则可以看到auth属性是Firebase User

您可以使用instanceof验证这一点:

constructor(private auth: FirebaseAuth) {
    auth.subscribe(
        (user) => {
            if (user) {
                console.log('user.auth is a User instance = ' + (currentUser instanceof firebase.User));
                let currentUser = user.auth;
                // ...
            } else {
                console.log('no user signed in');
            }
        }
    );
}