2017-06-12 26 views
0

我正在尝试在用户登录到我的应用后创建“欢迎,{用户名}”页面。在尝试将当前用户信息拉入我的视图时,我收到了未定义的错误,并且只能在componentWillMount包装器中加载用户数据。Firebase React本机当前用户混淆

组件“挂载”后,获取用户数据的最佳方式是什么?也许我不完全理解这个概念?

回答

0
var user = firebase.auth().currentUser; 
var name, email, photoUrl, uid, emailVerified; 

if (user != null) { 
    name = user.displayName; 
    email = user.email; 
    photoUrl = user.photoURL; 
    emailVerified = user.emailVerified; 
uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use 
       // this value to authenticate with your backend server, if 
       // you have one. Use User.getToken() instead. 
} 

如果使用JavaScript的火力

您可以通过此代码获取登录后用户