[英]what is returned on firebase.auth().onAuthStateChanged?
When I hover over onAuthStateChanged
it shows this: 当我将鼠标悬停在onAuthStateChanged
它将显示以下内容:
(method) firebase.auth.Auth.onAuthStateChanged(nextOrObserver: firebase.Observer<any, any> | ((a: firebase.User) => any), error?: (a: firebase.auth.Error) => any, completed?: firebase.Unsubscribe): firebase.Unsubscribe
It also seems to work if I do user: firebase.User
如果我执行user: firebase.User
它也似乎可以正常工作
firebase.auth().onAuthStateChanged((user) => {
console.log("data from stateChanged: ", user);
})
But when I try to access the properties of user, ie user.uid then I get error basically saying inaccessible. 但是,当我尝试访问用户的属性,即user.uid时,我得到的错误基本上是说无法访问。 So what exactly is the return type here and how do I access that? 那么,这里的返回类型到底是什么,我该如何访问呢?
onAuthStateChanged
returns either a firebase.User
or null
. onAuthStateChanged
情况传回firebase.User
或null
。 You need to null guard it and potentially cast as a firebase.User
in Typescript before accessing it's attributes. 你需要为null保护它,并可能铸成firebase.User
在打字稿访问它的属性了。
I'd recommend using the AngularFire2 and it's AngularFireAuth module, if you're using Angular; 如果您使用的是Angular,我建议您使用AngularFire2及其AngularFireAuth模块。 we've smoothed over some of these API concerns and have wrapped the callbacks in RxJS Observables. 我们已经解决了其中一些API问题,并将回调包装在RxJS Observables中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.