053_ Kartik
053_ Kartik

Reputation: 27

How we get username in firebase?

In firebase, we create user with email and password by using createUserWithEmailAndPassword. But when we verify the token and get the firebase user, It returns some properties like email, userid, uid, name,etc. Here we just send the email and password then How we get the user name even we are not passing user name to firebase. I know this is silly one but I am not able to understand how it is working. Please help me.

Upvotes: 1

Views: 1174

Answers (2)

Dharmaraj
Dharmaraj

Reputation: 50830

If you try to access firebase.auth().currentUser.displayName, then it will log undefined as you never set the display name. You should update the name using updateProfile method after the user signs up.

firebase.auth().createUserWithEmailAndPassword().then((userCred) => {
  const {user} = userCred
  user.updateProfile({displayName: "myNewName"}).then(() => {
    console.log("Name Updated")
    console.log(firebase.auth().currentUser.displayName)
  })
})

Upvotes: 2

Charith Jayasanka
Charith Jayasanka

Reputation: 4792

Try this

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
    // Name, email address etc
    String name = user.getDisplayName();
    String email = user.getEmail();
}

Upvotes: 0

Related Questions