How can I register a username in Firebase?

前端 未结 3 1238
醉话见心
醉话见心 2021-01-24 21:07

I am trying to implement the registration of a username in Firebase since it only gives me methods that are like the createUserWithEmailAndPassword(), but you can n

相关标签:
3条回答
  • 2021-01-24 21:15

    If you're using email/password auth with a username instead, you can simply index the users to email addresses in a sep path. Then when a user authenticates, look up their email in the index:

    /user_to_email_index/$user_name/ https://www.firebase.com/docs/web/guide/login/custom.html

    0 讨论(0)
  • 2021-01-24 21:25

    Try this,

    DatabaseReference database =   FirebaseDatabase.getInstance().getReference();
        User user = new User(firebaseUser.getUid(),
                firebaseUser.getEmail(),
                , firstName, photoURL); // add value as bean object
    
        database.child(ARG_USERS)
                .child(firebaseUser.getUid())
                .setValue(user)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                  // user data updated in firebase
                           }
    
    
                });
    
    0 讨论(0)
  • 2021-01-24 21:37

    You cannot store custom data within a firebase user per se, according to firebase documentation

    You cannot add other properties to the Firebase User object directly; instead, you can store the additional properties in your Firebase Realtime Database.

    Since each registered user has a unique id that you can access with

    FirebaseAuth.getInstance().getCurrentUser().getUid()
    

    once the user logs in, you can create a table in the realtime database that stores data of each user using your User class. Then you can query the database for the logged in user using the snippet above for the Uid.

    More info here: https://firebase.google.com/docs/auth/users

    0 讨论(0)
提交回复
热议问题