Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add email address as child in Firebase? [duplicate]

I am working on an Android App where I want a Firebase database like enter image description here

Basically, I want to verify email before creating a user on the app. Whenever a user registers in my app, First it will be checked whether the email address is available in the users database reference. if available, then only he is allowed to register. But I found that Firebase doesn't allow an email as a child. So How can I do it? Any other suggestion for achieving this in Firebase Database.

like image 570
Subham Kaps Avatar asked May 09 '17 07:05

Subham Kaps


People also ask

What is getInstance in Firebase?

getInstance(FirebaseApp app, String url) Gets a FirebaseDatabase instance for the specified URL, using the specified FirebaseApp. DatabaseReference. getReference() Gets a DatabaseReference for the database root node.

What is simultaneous connections in Firebase?

A simultaneous connection is equivalent to one mobile device, browser tab, or server app connected to the database. This isn't the same as the total number of users of your app, because your users don't all connect at once.

How do I change the realtime rule in Firebase?

Edit and update your rulesOpen the Firebase console and select your project. Then, select Realtime Database, Cloud Firestore or Storage from the product navigation, then click Rules to navigate to the Rules editor. Edit your rules directly in the editor.


1 Answers

Because Firebase does not allow symbols as . in the key, I suggest you encode the email address like this:

[email protected] -> name@email,com

As you probably see, instead of . I have used ,. To achieve this, you can use the following methods:

static String encodeUserEmail(String userEmail) {
    return userEmail.replace(".", ",");
}

static String decodeUserEmail(String userEmail) {
    return userEmail.replace(",", ".");
}
like image 149
Alex Mamo Avatar answered Sep 23 '22 09:09

Alex Mamo