【问题标题】:How to include firebase admin in angular project如何在 Angular 项目中包含 Firebase 管理员
【发布时间】:2019-10-16 08:35:44
【问题描述】:

我想在我的 Angular 7 项目中添加管理用户的功能,使用 firebase 进行用户身份验证。

我的应用程序在我的项目中成功地使用了用户的 Firebase 身份验证。

现在我想让我的程序的管理员用户能够列出用户、更新用户、添加用户、控制用户角色等。我不希望我的用户需要访问 firebase 管理控制台。

我的第一个测试只是使用 admin.auth().listUsers 函数列出 firebase 用户。有关于如何使用 node.js 执行此操作的很好的文档,但没有使用 angular 的下一步。

我的问题是需要定义变量“admin”。

当我使用node.js代码时:

var admin = require('firebase-admin');

我收到一大堆错误,例如:

./node_modules/google-gax/build/src/operationsClient.js 中的错误 找不到模块:错误:无法解析“/Users/Stan/Sites/google/dallas/node_modules/google-gax/build/src”中的“./operations_client_config” ./node_modules/google-auth-library/build/src/auth/googleauth.js 中的错误 找不到模块:错误:无法解析“/Users/Stan/Sites/google/dallas/node_modules/google-auth-library/build/src/auth”中的“child_process” ./node_modules/google-gax/node_modules/google-auth-library/build/src/auth/googleauth.js 中的错误 找不到模块:错误:无法解析“/Users/Stan/Sites/google/dallas/node_modules/google-gax/node_modules/google-auth-library/build/src/auth”中的“child_process”

当我不输入上述要求行时,唯一的问题是未定义“admin”。

我认为我错过了一些小的设置问题,但非常感谢任何帮助。

【问题讨论】:

  • firebase 管理员不打算在客户端使用。您可以使用 Firebase 规则创建“管理员”CRUD 功能。在github.com/firebase/friendlypix-web 以及其他项目中有这些类型的规则/限制的示例。

标签: angular firebase-admin


【解决方案1】:

admin sdk 仅适用于 nodejs。所以你不能在前端使用它。

您可以为此创建一个 Firebase 云功能。并将其部署到您的项目中。然后,您可以在 Angular 应用程序中调用该函数。

【讨论】:

  • 感谢您和 Alexander 的回复。哦,有趣,还要写一个后端进程。不知道为什么会这样。
  • Admin SDK 用于安全环境,如果您需要在浏览器中运行它,请使用 firebase web SDK
猜你喜欢
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 1970-01-01
  • 2021-06-26
  • 1970-01-01
  • 2022-08-05
相关资源
最近更新 更多