如何在 Angular 项目中包含 Firebase 管理员

sto*_*shb 1 firebase-admin angular

我想在我的 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”中的“./operations_client_config” /build/src' ./node_modules/google-auth-library/build/src/auth/googleauth.js 中的错误:找不到模块:错误:无法解析“/Users/Stan/Sites/google/”中的“child_process” dallas/node_modules/google-auth-library/build/src/auth' ./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”未定义。

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

Muh*_*ran 5

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

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