何时使用FirebaseAuth用户uid以及何时使用电子邮件作为标识符 [英] When to use FirebaseAuth user uid and when to use an E-mail as identifier

查看:134
本文介绍了何时使用FirebaseAuth用户uid以及何时使用电子邮件作为标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此 挖掘中的问题 一个跟进问题。



纠正我的假设,请我的学习曲线是积极的:)。如果让一个聊天应用程序具有Firebase作为后端存储,然后使用 FirebaseAuth.getInstance()。getCurrentUser()。getUid() 在聊天系统中作为聊天成员标识符使用,如果允许用户删除那里的帐户,并允许帐户链接,那么这是一个坏主意。 uid会改变,那会破坏数据库吗?我现在的下一个假设是,在聊天应用程序中有一个安全的用户ID,可以使用已登录的电子邮件地址,因为它是一个值得信赖的提供商
我的结论是从不使用 getCurrentUser()。getUid() uid作为用户的标识符或者?

getCurrentUser()。getUid()是个不错的主意,但是更好的办法是使用标识符电子邮件地址。我这样说是因为在用户正在删除账户而不是返回的情况下, uid 肯定是不同的。由于Firebase不允许按键中的点符号,因此电子邮件地址必须如下编码:


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


正如你所看到的, 。为了做到这一点,我使用这种方法重新注意到:

  static String encodeUserEmail(String userEmail){
return userEmail。替换(。,,);


static String decodeUserEmail(String userEmail){
return userEmail.replace(,,。);
}

希望能帮上忙。


With This Question in mined here´s a follow up question.

Correct me on my assumptions please my learning curve is aggressive :).

If making lets say a chat app having Firebase as backend storage, then using the FirebaseAuth.getInstance().getCurrentUser().getUid() uid inside the chat system as a chat member identifier, a bad idea if, you allow users to delete there account, and allowing account linking. The uid would change and that would break the database right?

My next assumption now is that to have a secure user id inside the chat app one can use the signed in E-mail address right because it´s a trusted provider!? My conclusion is to never use the getCurrentUser().getUid() uid as an identifierar for the user or?

解决方案

It's not a bad idea to use getCurrentUser().getUid() but a better idea is to use as an identifier the email address. I'm saying this because in the case in which the user is is deleting the account and than returns, the uid will be for sure different. Because Firebase does not allow the dot symbol . in the key, the email address must be encoded like this:

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

As you probably see, i have changed the . with ,. To do this, i recomand you using this methods:

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

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

Hope it helps.

这篇关于何时使用FirebaseAuth用户uid以及何时使用电子邮件作为标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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