尝试在angularfire2中获取currentUser。什么类型暴露了这个?
https://firebase.google.com/docs/reference/js/firebase.auth.Auth
对于我来说,探索这个观察结果并不明显:constructor(private auth: FirebaseAuth) {
auth.subscribe((user) => console.log('user is', user));
}
答案 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');
}
}
);
}