【问题标题】:firebase SDK error- Cant find variable adminfirebase SDK 错误 - 找不到变量管理员
【发布时间】:2019-06-25 06:11:34
【问题描述】:

当我使用下面的代码时,我收到一个错误:- 找不到变量 admin

    admin.auth().getUserByEmail('svd@gmail.com')

      .then(function(userRecord) {
        // See the UserRecord reference doc for the contents of userRecord.
        //console.log("Successfully fetched user data:", userRecord.toJSON());
        alert(userRecord.toJSON());
      })
      .catch(function(error) {
        console.log("Error fetching user data:", error);
      })

【问题讨论】:

  • 问题不在于您提供的代码。它位于 admin 定义或导入的任何位置。
  • 您将此标记为关于 React 的问题。您是否尝试在客户端环境中使用 Admin SDK?你应该知道你不能这样做。它仅适用于服务器环境。

标签: javascript reactjs firebase react-native firebase-authentication


【解决方案1】:

尝试这样做并告诉我这是否适合您。我也不确定它是来自您的 firebase JSON 数据的提取问题还是数据库问题。

就这个管理变量而言,它看起来像是一个 firebase 实例,请确保您在项目中正确初始化了 firebase。按照此链接将其添加到您的项目中,然后在您要获取详细信息的特定类中导入或初始化它。 Add Firebase to your JavaScript Project

认为您可能已经存储了一些数据。做这样的代码会起作用:

firebase.auth().getUserByEmail('svd@gmail.com')
  .then((response) => response.json())
  .then((responseJson) => {
     /* check the data is it coming in your console or you can simply put it inside the alert() */
     console.log(responseJSon);
  })
  .catch((error) => {
    console.log("Error fetching user data:", error);
});

注意:在实现之前,请确保您已在代码中初始化admin 变量,否则它将无法对空变量或未定义变量执行操作。确保也是如此。

【讨论】:

  • 看起来您正在以 Java 风格而不是 JavaScript 风格定义 admin。很确定那是行不通的。
  • 我的代码有适当的编辑。谢谢@DougStevenson 让我知道,我也认为这不会起作用。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-23
  • 2019-03-14
  • 1970-01-01
  • 1970-01-01
  • 2019-12-28
  • 2019-02-22
相关资源
最近更新 更多