arcrub
arcrub

Reputation: 170

Firebase - fetching a user's account without specifying UID nor email address

I have made an Ionic-Angular app that generates fake data in bulk to my Firebase database. It can generate multiple kinds of data separately:

So that I know which documents are associated with which user, I would like the user's uid property to be the name of all of his/her documents (a.k.a. the user's document in the "foo" collection would be located at foo/${uid}).

Hence, if I want to generate 10 documents for the "foo" collection, I need the uid of 10 users, whichever they are. Is it possible to fetch the latter? It would be an equivalent to admin.auth().getUser(uid), but without a specified uid (hence giving me a random, unspecified user).

I could store uids in a separate document when I generate the accounts to then fetch them when I need them, but I don't want to go through the hassle of doing so and the logic that comes with it.

Upvotes: 0

Views: 93

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317412

What you're trying to do (listing users in Firebase Auth) from a client app isn't possible. It would be a massive security hole to allow end users to discover lists of all other end users by default.

If you want to list users, you should write backend code using the Firebase Admin SDK. It has a way to list all users. If you need to invoke this from the client app, you will need to find a way to wire that up yourself, perhaps using Cloud Functions or some other backend.

Upvotes: 1

Related Questions