我想为 Telegram 机器人读取一次 Firebase 数据,但出现此错误:
D:\Projects 2016\Web\BOT\node-telegram-bot-api-sedric-bot\src\index.js:39
var userId = firebase.auth().currentUser.uid;
^
TypeError: Cannot read property 'uid' of null
我使用了来自 Google 教程的这个,这是我的功能:
function readonce() {
var userId = firebase.auth().currentUser.uid;
return firebase.database().ref('/users/' + userId).once('value').then(function(snapshot) {
var username = snapshot.val().username;
// ...
});
}
readonce()
我阅读了网上所有的教程,但我无法理解如何通过java脚本读取数据
最佳答案
您似乎正在使用 Firebase Admin SDK在你的 Node 脚本中。 Admin SDK 作为管理级别 super 用户运行,没有定义的身份。因此,没有 firebase.auth().currentUser
。
这听起来像 XY problem : Node 脚本未以特定用户身份运行。那么您要查找谁的用户名?您想对用户名做什么?
关于javascript - 在 Node 中使用 firebase 时出现错误 "Cannot read property ' uid' of null”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44663983/