问题
I'm building an Android app and I want my users to be Auth then added to the database. For now I'm only doing the Auth with an email and password, then I click register and the user is created in the Auth section in the Firebase console.
But I also want my users to be added in the database. I want to add more fields (such as name, address etc) which will be stored in the users database in Firebase.
I just don't really see how to do that. Anyone could explain please?
Thanks!
回答1:
You should create a node where you save your users, like this:
users: {
userID1: {
name: 'Raph'
},
userID2: {
name: 'Devid'
}
}
Every logged user has a unique uid
that you can use as key. You can find it in the authToken when you log your user in.
NOTE this is just a normal node in Firebase that you use to save user's data. It is an alternative solution to the Firebase generated users.
回答2:
Here is one way to store the registered details in database,
Map<String, String> parameters = new HashMap<>();
FirebaseDatabase mFirebaseInstance;
parameters.put(Constant.TAG_USER, strUsrS.trim());
parameters.put(Constant.TAG_PASS, strPassS.trim());
//use this if needed(pushId)
String pushId = mFirebaseInstance.getReference(YOUR TABLE NAME).getRef().push().getKey();
parameters.put(Constant.TAG_KEY, pushId.trim());
mFirebaseInstance.getReference(YOUR TABLE NAME).getRef().child(strUsrS.trim()).setValue(parameters);
Try this implementation and execute... Thankyou
来源:https://stackoverflow.com/questions/38142123/create-user-in-database-after-firebase-auth-android