When to use FirebaseAuth user uid and when to use an E-mail as identifier

有些话、适合烂在心里 提交于 2019-12-12 02:44:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/44100005/when-to-use-firebaseauth-user-uid-and-when-to-use-an-e-mail-as-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!