Can the Firebase user id change? What I talk about is this, FirebaseAuth.getInstance().getCurrentUser().getUid() If user delete his account like it is described here Manage-users. I was assuming the getUid() id was tied to the E-Mail right, or!?
I was assuming the getUid() id was tight to the E-Mail right, or!?
Not "tied" in the sense of "derived from". "Tied" in the sense of "associated with".
Remember that the email can be changed. When that happens, of course the id is left as is.
You can easily test this in the Firebase console by creating a new user, checking the ID, changing the email and checking that the ID does not change, then deleting the user and creating a new user with the same email and checking that a new ID has been assigned.
As said by #user663031, the answer "no" is correct.
To add on to #user663031's answer, I'm working on a project, but I have to switch between the live database and the test database. I created a user (in firebase authentication) in both test & live environment with the same email address & password, however the id's are different.
In order to achieve proper tests in both environments, I had to change id stored in real time database so that it matches the "unchangeable id" in authentication.
Related
I am making an app, and in that app, users login and I am storing their information; however, I have noticed that I don't have a users' password information after they register. Is it a good idea to store users' password when they register through Firebase? And is there a point where I will need their passwords? I want to make sure before I proceed further. Thanks!
You do not do that.
Use the (awesome, amazing) Firebase authentication system.
Click right here:
on the left, to see all the users - click "Authentication".
You never see / you cannot see their passwords.
You don't handle or touch the passwords at all.
In the Android or iOS app, you get the userid - and that's it.
The answer by #PeterHaddad shows perfectly how to do that.
That's the first and most basic step in any Firebase ios/droid app.
In your data you'll have a "table" called probably "userData/" and that's where you keep all data about the user. (For example, you may store their address, real name, shoe size .. whatever is relevant in your app.)
Note - FBase is so amazing, your users can also connect with other methods (phone, etc). For your reference in the future, that is explained here
You don't need to store the password in the firebase database, after you authenticate the user using createUserWithEmailAndPassword the email and other info will be stored in the authentication console. So you do not need the password in the database, all you need is the userid to connect auth with database.
FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String useruid=user.getUid();
I am making an android app that when a user register an account on firebase, he saves his email, phone number and password. but when he wants to login, he uses his phone number and password. Because of that requirement I must also make the phone number unique There are a number of ways too do this but my options are limited because the database is already being used by a working system and me making changes to it will cause the other system not to work. The best way to solve my problem without affecting the other system is by modifying the rules to prevent a user from adding an phone number that already exist.
My database structure is like this
users {
userID {
name: "John"
phone: "2342222"
address: "23rd Avenue"
email: "email#mail.com"
}userID 2 {
name: "Mark"
phone: "2342222"
address: "5th Avenue"
email: "email#mail.com"
}
}
Now my rules look like this
service cloud.firestore {
match /databases/{database}/documents {
match /Users/{anything=**} {
allow write: if auth != null && !data.exists() && data == request.auth.uid;
}match /Users/{userId} {
allow read: if request.auth.uid == userId;
// I need a rule maybe here that will allow me write phone number to the database
// If the number doesn't exist in my entire Users database.
}match /user-compare/{anything=**} {
allow read: if true;
}
}
}
Ive tried
allow write: if request.auth.uid == userId && !request.resource.data.phone in resource.data.phone;
I want to make sure that a user can only read and write data inside its user ID, but my rules should be the one to prevent duplicate data not the source codes because due to the way the other system is setup, if multiple users have the same phone number, it will crash, and right now my app is the only way to make multiple users with the same phone number.
I know I can create a new collection to holder the numbers and then check if the number exist there for the registration process, but if anyone uses the other system to register, the numbers will not appear in this new collection.
The best way is if I can write a rule. My problem is a bit different from what I've seen and I hope I'm explaining properly. any help would be appreciated, thanks.
I couldn't solve it with rules no matter what I tried but Using Firebase Admin SDK will allow a developer write/edit/view information in Authentication section of the Service and this will allow you make the changes and validate them. You can learn more Here. This can be added as a dependency on the app but Due to the nature of the service I didn't feel that It'll be safe giving users access to an app with admin privileges. But this is a solution when you have the application for example in the office and users only have access to it in a save environment and can be used to add more functionality for staffs or authorized member's use.
For me, what solved my security concerns was to install the Admin SDK on a server. For my problem this can be used in two ways. I can make a custom authentication found Here and use that to sign in users using their phone number and password. But what I chose to do was make a simple API to take the phone number and check if there's any email address associated with it. if Yes retrieve the email and use that together with the password and sign in with email and password. so basically it uses the usual email and password sign in, but the user input their number and password instead. This was what worked for me and I hope it helped someone in a similar position.
I am developing an android application where older kids can pick up younger kids and walk to school. With the application, the authenticated (email and password) younger kid can choose between three addresses to get picked up. I have a user node and an address node.
The problem is that every time a user picks an address, the username child is overridden. Therefore there will only be one username per address.
My database structure looks like this:
database.child("Addresses").child(m1.getStreet()).child("username").setValue(name);
database.child("Addresses").child(m2.getStreet()).child("time").setValue(time);
database.child("Addresses").child(m3.getStreet()).child("address").setValue(address);
I thought about using the push function, but I don't think it can be used in this context. Any ideas?
setValue() will override everything in the existing map. Use updateChildren() if you want to add/update values and keep the old data.
If you have unique usernames or if you can get the keys in User, you can directly use that as a key:
database.child("Addresses").child(m1.getStreet()).child("users").child(name).child("username").setValue(name);
database.child("Addresses").child(m2.getStreet()).child("users").child(name).child("time").setValue(time);
database.child("Addresses").child(m3.getStreet()).child("users").child(name).child("address").setValue(address);
I have authenticated my user using phone authentication, and the user object that is returned has this long string when I call user.getUid() :
dn27dhJK..... (some long string).
If I authenticate this user on some other device (using my phone number etc), will user.getUid() always be the same ?
EDIT: From the documentation: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser
public abstract String getUid ()
Also: Google Play services Returns a string used to uniquely identify
your user in your Firebase project's user database. Use it when
storing information in Firebase Database or Storage, or even in your
own backend.
This identifier is opaque and does not correspond necessarily to the
user's email address or any other field.
It is unclear if this id remains constant or not.
When you first verify the phone number (or first sign in with a social provider, or call createUser), a user account is created - and thus a new unique UID id created. From that moment on, that user/phone number will remain associated with that account/UID. No matter if they re-verify on the same or a different device.
If you delete the account, a new account+UID will be generated when you use that same phone number next time.
If you're using Firebase Authentication in your project:
Remember
Firebase will generate a single unique key(i.e. UID) on registration of a/c whether using Email/Phone number.
This key remain associated to that a/c untill a/c is exist in firebase authentication list.
If your app is uninstalled on phone & then a/c is open in another then we can fetch that key from Firebase cloud auth. service.( UID remain safe).
This Uid is created when the user signs up and is linked to the phone number that you used. When you sign in you will get the same uid. But if you try to sign up again with the same phone number, it will basically give an error saying this phone number is already signed up.Hope that explains!
The Firebase Android SDK for analytics provides a method named setUserId(String id), now i enabled firebase logging and every time i called the method setUserId(1234) i see this in the logs Setting user property (FE): _id, 1234.
My question is how come the Firebase dashboard does not let us filter by this property, there is no property not for userId and not _id, i even tried to add _id as a property in the dashboard but Firebase does not allow property names to start with an underscore.
Do i really have to stop calling that method and just do setUserProperty("userId", 1234) or am i missing something...
I have spent a few hours on this and found the answer i was looking for more or less, hopefully this might save someone else some time.
The only way to filter by Firebase's User Id property is by creating an audience, there you will be able to pick the user id property that is supplied from the setUserId(String id) method.
It is a downer though because you won't see any events for the user/user's you want from before the audience was created.
I was scratching my head with this issue. Initially, I felt so dumb when I could not find how to use user id for filtering in Firebase analytics dashboard that I am setting with official API setUserId(). When I try to look for answer, I realized that I am not the only one. Finally, this is how I was able to filter events based on user id.
In Android Code, I set user id using setUserId() method. When I read bigQuery has this property as user_id, I thought to give it a try by adding a new user property in Firebase Dashboard with the hope that it will fetch the reported id.
And... that worked...Now I can filter new events based on user id.
In audience you have to select contains, exactly match or regular expression for a field.
So to filter for a user you have to add all your users to the audience, which looks cumbersome.
Isn't using setUserProperty is better? Have you faced any problems with using it ?