in the app, which logs the user in only through phone authentication.
now the question is can I get the user id from his phone number(not the user id of the current user though).
I have the access to other users phone number in the app, and I want to get their id for further use.
is it possible in flutter with firebase at the backend?
Looking up the UID for a user based on either phone number or email address is considered a sensitive operation. For this reason such operations are only available in the Admin SDKs, which are designed to be used in trusted environments, such as your development machine, a server you control, or Cloud Functions. For more on these, see the bottom two code samples in looking up user data in the documentation.
If you want to perform such operations from your client-side code, your two main options are:
Store the required mapping in a cloud-hosted database, such Firebase's Realtime Database or Firestore, as Huthaifa also answered.
Create your own custom API on a server or Cloud Functions where you lookup the user through the Admin SDK. Your client-side application code can then call this custom API.
In both of these cases you are in full control of what data you share, and how you secure access.
Sure you can, there are multiple approaches for this, if you post your structure for the user model, or how you are storing them in firebase.
You can run a simple Firebase query like this example:
FirebaseFirestore.instance.collection('users').where('phoneNumber', isEqualTo: thePhonenumberOftheuserYouwant2GetUIDfor).get()
You can also store the available\accessible contacts for every user in their user document, and when your user logs in, it'll fetch all their allowed user numbers.
The more information you provide to your problem, the more StackOverflow can provide you back.
Related
In a classroom, I'll provide to 100 users, 100 android devices, where they'll have to open an UNITY app.
Inside the app, I don't want the users to bother to enter any login, any email, any password.
So I guess they would need to be connected "automatically" to the same firebase account.
Then, they'll need to select one of the avatars available in firestore, with which they'll play and the app will save their avatar progress in firestore.
Is it possible to have so much players and devices using the same firebase account at the same time for that purpose ?
I'd probably first look at signing in each device anonymously. That way each device/app instance has a unique, persistent identifier, without having the user enter any credentials.
You can then also use the UID in your database to have indicate the avatar that each user/device claims, and in the security rules of that database, to ensure users can only access data they're authorized for, and for example that each avatar can only be claimed by one user.
I want to get User Data from firebase, I need the diplayName of a User. is there any way to get the displayName of a other user with his uid?
There is no way to look up information about another user in Firebase Authentication by using the client-side SDKs of Firebase, as that would be a security risk.
There are two common ways to allow searching the users in a secure way:
Write information about each user to a database (such as Cloud Firestore or the Realtime Database) when they register, and then search the database when needed. That way your code controls what data gets written and thus is searchable.
Firebase has Admin SDKs that run in trusted environments, such as your development machine, a server you control, or Cloud Functions. These SDKs have options to list users, which means you can search them. If you wrap one of the Admin SDKs in a custom API that you build and secure yourself, you can then call that from your Flutter code.
Also see:
React native firebase authentication searching
You can't get the name, or any other details of a user that is not currently signed in using FirebaseAuth.
Instead, you must create a node in your database where you store the name, and any other necessary details by querying the database.
We have two apps, one for the client and one for the admin (similar to Uber's user and driver apps). In both apps, when users attempt to authenticate, cloud functions triggers a new user creation and it saves a document in users' collection in cloud firestore with some data, like phone number, email, etc. We are encountering a an issue that when the user or the "driver" registers, the data model that is saved in the cloud firestore has different fields and they are different from one another.
When a new user is registering, how can I trigger in the cloud function that can identify whether it is from the "user" or the "drive" app?
There's not going to be anything in the Cloud Functions auth trigger that tells you which app registered the new user. Within a Firebase project, all user accounts are effectively shared between all apps, and all users will have the same permissions between those apps.
If users slot into different categories based on the app they used to sign up, you'll have to create that distinction on your own, perhaps with something you write to a database. If this isn't acceptable from a security perspective, you should use two different projects instead to keep everything separate.
I have a Firebase project, which I'm currently using with android. I need to programmatically fetch details of the users authorized along with the UID, Email, etc. Exactly the way it is shown in firebase (with the search), this web portal will be given to the vendor or the person using it to verify the user's authenticity.
I've attached the screenshot from Firebase, I'm hoping to replicate it the same way with the search. If this is possible, how do I go about doing this?
It's not possible to list users from an Android app, using only the Firebase Authentication SDK. You can list users using the Firebase Admin SDK, but that can only be run on a backend you control, using service account credentials for your project.
It might be easier if you store user info in a database, to be queried by client code, rather than try to have your app try to access auth data directly.
I have integrated Firebase's Facebook and Email Login into my iOS application.
Although, I would like to only store the Firebase User ID in my API database.
Therefore from my backend server (say Ruby) how can I query firebase to get say the user's name and user's email address given that I have their Firebase User UID.
Thanks
To directly read user data for arbitrary users of your app, you'd use the Firebase Admin SDK: https://firebase.google.com/docs/admin/setup. This specific page shows how to read user data: https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
Reading user data through the Admin SDK is currently only available for Node.js and Java. Since Ruby isn't on this list, you'll need to keep the user information elsewhere. The Firebase Database is a common place to store such data, so that any platform can access it through its REST API.