自定义Firebase用户身份,不使用Firebase用户uid [英] Custom Firebase user identity not using the Firebase user uid

查看:144
本文介绍了自定义Firebase用户身份,不使用Firebase用户uid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩 FirebaseUI-Android ,并且询问什么是ID在唯一标识用户时使用。 FirebaseUI管理身份验证权并返回 IdpResponse 对象。这可以是例如Facebook,Twitter,Phone等等。这是格雷谢谢大家。



因为 FirebaseUser.getUid()可以在用户删除/重新创建帐户时更改,因此我不希望将我的用户数据与 FirebaseUser.getUid()令牌关联。未来,如果我决定让用户擦拭那里的账户,当用户回来时,用户的所有用户历史记录都不能访问。同样在未来,如果我将系统迁移到某个地方,那么uid将不会那么方便吗?

现在我创建了这个包装器(下面的代码)来创建一个根据 IdpResponse 中的数据外推唯一的ID。真的不知道,但我想这样做,除非有Google 2.0,否则就不会有身份证的冲突。 Twitter2.0 :)正确。与此同时,更容易在系统中删除错误,因为id不是UUID。



这是处理用户id问题的一种推荐方法。我真的需要一些反馈和陷阱警告。

  @Override 
public String getUserId(){
String userId;
FirebaseUser user = getInstance()。getCurrentUser();
if(user.getEmail()!= null)
//用户使用电子邮件登录
userId = user.getEmail()。replace(。,,) ;
else if(user.getPhoneNumber()!= null){
//用户用电话
登录userId = user.getPhoneNumber();
} else
//用户使用Twitter或Facebook登录
userId = user.getUid();
返回userId;



$ b $ p
$ b $ p $最让我困扰的是Twitter或Facebook,因为我还需要使用 FirebaseUser.getUid() IdpResponse.getIdpToken()对我们来说更好吗?

解决方案

你在你的帖子中提到,使用uid不是最好的选择。如果用户删除了自己的帐户,并尝试创建另一个帐户,则会生成另一个 uid 。所以在这种情况下,他会损失所有的数据历史。
识别用户的最好方法是使用电子邮件地址。该电子邮件地址是独一无二的,易于使用,如果将来希望将 Google帐户 Facebook帐户连接 Twitter帐户,根据电子邮件地址,您将能够做id。由于Firebase不接受密钥中的符号,因此我建议您将电子邮件地址编码如下:


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

正如你所看到的,我改变了点符号与一个昏迷。为了达到这个目的,我使用这个方法重新命令:

$ p $ static String encodeUserEmail(String userEmail){
return userEmail.replace (。,,);


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

希望能帮上忙。


I´m playing around with the FirebaseUI-Android and have a question about what ID to use when uniquely identify users. The FirebaseUI managed the authentication right and return the IdpResponse object. This can be e.g. Facebook, Twitter, Phone and more.. This is grate thanks everyone behind this.

Because the FirebaseUser.getUid() can change when user delete/recreate his account therefore i don't want to link my users data with the FirebaseUser.getUid() token.

In the future if I decide to let user wipe there account the uid will change when user come back and all user history for that user in my system is not accessible anymore right. Also in the future if I migrate my system to someplace the uid will not be that handy to have around right?

Now I created this wrapper(code below) to create a unique ID extrapolated from the data inside the IdpResponse. Dunno really but I figure doing it this way there will never be a "id" collision unless there´s a Google2.0 e.g. Twitter2.0 :) right. And at the same time it´s easier to debunk bugs in the system because id´s are not UUID.

Is this a recommended way to handle the user id problem. I really need some feedback and pitfalls warnings about this.

@Override
public String getUserId() {
    String userId;
    FirebaseUser user = getInstance().getCurrentUser();
    if (user.getEmail() != null)
        // User sign in with E-Mail
        userId = user.getEmail().replace(".", ",");
    else if (user.getPhoneNumber() != null){
        // User sign in with Phone
        userId = user.getPhoneNumber();
    }else
        // User sign in with Twitter or Facebook 
        userId = user.getUid();
    return userId;
}

What bother me most with this is the Twitter or Facebook since I still have to use the FirebaseUser.getUid(). Is the IdpResponse.getIdpToken() better to us?

解决方案

As you mentioned in your post, using the uid is not the best option. If the user removes his account and than tries to create another account, another uid is generated. So in this case, he losses all data history. The best way to identify users, is to use the email address. The email address is unique, easy to use and if want in the future, to link a Google account with a Facebook account and with a Twitter account, based on the email address, you'll be able to do id. Because Firebase does not accept . symbol in the key, i suggest you encode the email address like this:

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

As you probably see, i have changed the the dot symbol . with a coma ,. To achive 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.

这篇关于自定义Firebase用户身份,不使用Firebase用户uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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