How do you include a username when storing email and password using Firebase (BaaS) in an Android app?

前端 未结 3 1420
野的像风
野的像风 2020-11-27 16:56

The Firebase createUser() method takes an email and password field, but what if I want to also allow the user a custom username similar to Snapchat, Instagram,

相关标签:
3条回答
  • 2020-11-27 17:33

    Show a form with three fields:

    1. Username
    2. Email address
    3. Password

    Send the latter two to Firebase's createUser() method. Then in the completion callback for that, store all information in your Firebase database.

    var userName, emailAddress, password;
    
    // TODO: read these values from a form where the user entered them
    
    var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
    ref.createUser({
      email    : emailAddress,
      password : password
    }, function(error, authData) {
      if (error) {
        console.log("Error creating user:", error);
      } else {
        // save the user's profile into the database so we can list users,
        // use them in Security and Firebase Rules, and show profiles
        ref.child("users").child(authData.uid).set({
          provider: authData.provider,
          name: userName
        });
      }
    });
    

    See this page on storing user data in the Firebase docs for more information.

    0 讨论(0)
  • 2020-11-27 17:46

    Yes, there is a way how to update user info in Firebase. All you need - to read this article in Firebase docs and implement method described here Update user info

    Using this method you can update diplayName property of FirabaseUser object. Just set user name for displayName property and commit your changes.

    I hope this will help you.

    0 讨论(0)
  • 2020-11-27 17:47

    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_EMAIL, strEmailS.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

    Hope that you aware about how to alter(create) table with required fields in firebase.

    Related question & discussion with solutions

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