问题
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