从javascript中访问firebaseUser'创建'时间戳

问题描述 投票:0回答:1

我想使用AngularFire直接从我的Angular应用程序的run函数中的firebaseUser对象中读取“Cr​​eated”时间戳(可在Firebase控制台的Authentication> USERS部分中找到)。

e.g

FirebaseAuth.$onAuthStateChanged(function(firebaseUser) {
    console.log(firebaseUser.created)
}

对象的任何位置都有时间戳吗?我试图避免在此时调用数据库。

谢谢你的帮助。

angularjs firebase firebase-authentication angularfire
1个回答
2
投票

您可以在创建新帐户时在数据库中添加创建日期:

Users
  useruid <-- from the console
     name: userx
     email: [email protected]
     creationdate: 2018-02-10
  useruid
     name: usery
     email: [email protected] 
     creationdate: 2018-03-01

还要检查一下:

https://firebase.google.com/docs/reference/js/firebase.User

或者使用metadata检索它,如下所述:

creationTime:

创建用户的日期,格式为UTC字符串。例如,'星期五,2017年9月22日01:49:58 GMT'。

或使用Admin SDK:

admin.auth().getUser(uid).then(function(userRecord) {
console.log("Creation time:", userRecord.metadata.creationTime);
});

https://firebase.google.com/docs/reference/admin/node/admin.auth.UserMetadata

© www.soinside.com 2019 - 2024. All rights reserved.