Skip to content Skip to sidebar Skip to footer

How To "name" Data In Firebase From Signup Email

When storing users in firebase, How do you display the node as their email rather than the characters displayed in the image. I tried a bunch of different things and keep getting e

Solution 1:

See the Firebase documentation on storing user data:

ref.child("users").child(authData.uid).set({
  provider: authData.provider,
  name: getName(authData)
});

As you'll see, that stores each user under their uid, which is guaranteed to be unique across all providers.

If you instead want to store the users under their email address, you'll have to do some extra work. Firebase keys cannot contain certain characters (most notable dots: .) that are present in email addresses, so you'll have to encode the email address.

var encodedEmail = authData.password.email.replace('.',',')
ref.child("users").child(encodedEmail).set({
  provider: authData.provider,
  name: getName(authData)
});

It's most common in cases like this, to actually store the user under their uid (as in the first snippet) and to additionally store a mapping from the (encoded) email address to the uid. That way you can easily get the user both by their uid and by their email address:

ref.child("users").child(auth.uid).set({
  provider: authData.provider,
  name: getName(authData)
});
var encodedEmail = authData.password.email.replace('.',',')
ref.child("emailMappings").child(encodedEmail).set(auth.uid);

Post a Comment for "How To "name" Data In Firebase From Signup Email"