You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 08:44:52