Extend Firebase User

后端 未结 2 2042
礼貌的吻别
礼貌的吻别 2021-01-25 07:45

After authenticating the user and updating the FirebaseUser table, I would need to save other extra data such as age, gender, address etc. I would like to use the R

2条回答
  •  悲哀的现实
    2021-01-25 08:13

    That's correct, to get the current user's unique ID you can use:

    FirebaseUser.getInstance().getCurrentUser().getUid();
    

    And you can then store details about a user into the Firebase Realtime Database using that unique ID as a key, something like:

    FirebaseUser user = FirebaseUser.getInstance().getCurrentUser();
    String userId = user.getUid();
    
    DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference("users");
    
    HashMap userDetails = new HashMap<>();
    message.put("name", "P. Sherman");
    message.put("age", 50);
    message.put("gender", "male");
    message.put("address", "42 Wallaby Way, Sydney");
    message.put("email", user.getEmail());
    
    messagesRef.child(userId).setValue(userDetails);
    

提交回复
热议问题