React Native 与 Expo:是否需要 firebase-admin?

React Native with Expo: is firebase-admin necessary?

我需要在身份验证过程之前获取我的 firebase 数据库。 我的 firebase 规则仅限于经过身份验证的用户进行读写。

所以我安装了 firebase-admin。

在App.js

import * as admin from 'firebase-admin';

并在初始化后

 const serviceAccount = require("./pathtocredentials.json");
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://myappdbname.firebaseio.com"
  });

这是我遇到的错误:

The package at "node_modules\firebase-admin\lib\firebase-namespace.js" attempted to import the Node standard library module "fs". It failed because React Native does not include the Node standard library. Read more at https://docs.expo.io/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo Failed building JavaScript bundle.

所以我搜索并..."Since your app is running inside JS VM on either iPhone or Android, the only way to access filesystem is to use react-native-fs"

我想要的只是在让用户进行身份验证之前检查我的数据库是否存在用户。我是否需要 firebase-admin 和 react-native-fs?

firebase-admin 不适用于网络前端代码。它用于后端代码 运行 nodejs。您将无法在 React 或任何浏览器环境中有效地使用 firebase-admin。最重要的是,如果您只是想从前端查询数据库,则没有必要。

您真正需要做的就是read data using the normal Firebase JavaScript API for web. You can tell if a node exists in the database by checking if its DataSnapshot object actually exists