Create user in database after Firebase Auth (android)

不羁的心 提交于 2020-01-02 01:04:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!