如何在 Firebase 中将电子邮件地址添加为孩子? [英] How to add email address as child in Firebase?

查看:19
本文介绍了如何在 Firebase 中将电子邮件地址添加为孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Android 应用程序,我想要一个类似 Firebase 的数据库

I am working on an Android App where I want a Firebase database like

基本上,我想在应用程序上创建用户之前验证电子邮件.每当用户在我的应用程序中注册时,首先会检查电子邮件地址是否在 用户 数据库参考中可用.如果可用,那么只有他被允许注册.但我发现 Firebase 小时候不允许发送电子邮件.那么我该怎么做呢?在 Firebase 数据库中实现此目标的任何其他建议.

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.

推荐答案

因为 Firebase 不允许在 key 中使用符号作为 .,我建议你像这样编码电子邮件地址:

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

name@email.com -> name@email,com

name@email.com -> 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(",", ".");
}

这篇关于如何在 Firebase 中将电子邮件地址添加为孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆