Firebase 列出所有用户 [英] Firebase list all users

查看:22
本文介绍了Firebase 列出所有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 firebase admin sdk,但是当我尝试这样做时:admin.auth() 它给了我一个错误提示错误:默认 Firebase 应用不存在.确保在使用任何 Firebase 服务之前调用 initializeApp()当我使用普通sdk时,应用程序已经初始化,如何初始化admin-sdk以便我可以列出所有用户?

I'm trying to use the firebase admin sdk but when I try to do this: admin.auth() it gives me an error saying Error: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services The app is already initialized when I use the normal sdk, how to I initialize the admin-sdk so I can list all users?

推荐答案

Admin SDK 旨在用于受信任的环境,例如您的开发机器、您控制的服务器或 Cloud Functions.它不是专门为在客户端代码中使用而设计的,因为这样做会让您应用的任何用户都有权访问您的整个 Firebase 项目.

The Admin SDK is designed to be used in trusted environments, such as your development machine, a server you control, or Cloud Functions. It is specifically not designed to be used in client-side code, as doing so will gives any user of your app privileged access to your entire Firebase project.

如果您想在您的应用中显示用户列表,两种常用方法是:

If you want to show a list of users in your app, the two common approaches are:

  • 将有关用户的必要信息存储在云数据库(例如 Cloud Firestore 或实时数据库)中并从那里读取,使用数据库的服务器端安全规则确保用户只能访问他们正在访问的信息授权.
  • 将来自 Admin SDK 的必要调用封装在您创建的自定义服务器端 API 中(例如,在您控制的服务器上或在 Cloud Functions 中),使用自定义代码确保用户只能访问他们的信息重新授权.

另见:

这篇关于Firebase 列出所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆