Firebase NodeJS函数报错:getUid is not a function 求助
解决Firebase云函数获取用户UID的错误
问题出在你调用了不存在的getUid()方法,Firebase Admin SDK返回的UserRecord对象里,UID是直接作为属性存在的,不是通过方法获取。
修改代码如下:
admin.auth().getUserByEmail("email@email.com") .then(function(userRecord) { response.json({ uid: userRecord.uid // 直接访问uid属性 }); console.log("Successfully fetched user data:", userRecord.toJSON()); }) .catch(function(error) { console.log("Error fetching user data:", error); response.status(500).json({ error: error.message }); // 补充错误处理逻辑 });
另外注意原代码的两个细节问题:
response.json()语句末尾缺少分号- 未添加
.catch()捕获异常,补上后能避免函数因未处理错误崩溃
内容的提问来源于stack exchange,提问作者Paul VI
相关产品推荐
相关产品推荐

