Facebook Firebase-将匿名用户转换为登录用户?

Facebook Firebase-将匿名用户转换为登录用户?,facebook,authentication,firebase,anonymous-users,Facebook,Authentication,Firebase,Anonymous Users,上下文:在我的iOS游戏中,我希望允许用户在不登录的情况下进行游戏(在Firebase中匿名验证以保存用户数据),但也允许他们使用Facebook登录以解锁其他游戏 我正在尝试修改,将Twitter登录改为匿名登录: "users": { "$userid": { // Require the user to be logged in, and make sure their current credentials // match at least one of

上下文:在我的iOS游戏中,我希望允许用户在不登录的情况下进行游戏(在Firebase中匿名验证以保存用户数据),但也允许他们使用Facebook登录以解锁其他游戏

我正在尝试修改,将Twitter登录改为匿名登录:

"users": {
    "$userid": {
      // Require the user to be logged in, and make sure their current credentials
      // match at least one of the credentials listed below, unless we're creating
      // a new account from scratch.
      ".write": "auth != null && 
        (data.val() === null || 
        (auth.provider === 'facebook' && auth.uid === data.child('facebook/id').val() || 
        (auth.provider === 'anonymous' && auth.uid === data.child('anonymous/id').val()))"
    }
  }
我不知道这些规则将如何进行转换。特别是说:

  • 用户以匿名方式进行身份验证,并且能够使用存储在
    users/“$userid”/anonymous/id
    下的匿名uid创建规范用户记录。这是允许的,因为用户已通过身份验证,并且用户对象是第一次设置的(
    auth!=null&&data.val()==null

  • 由于已验证用户的匿名id存储在用户树中(
    auth!=null&&(auth.provider=='anonymous'&&auth.uid===data.child('anonymous/id').val())
    ),因此允许对
    用户/“$userid”/
    进行任何后续写入操作

  • 用户登录到facebook。现在,
    authData
    包含facebook uid,该uid尚未写入
    用户/“$userid”/facebook/id
    。写入该位置失败,因为安全规则不允许

  • 因此,匿名用户只有在facebook身份验证完成后才能访问facebook uid。此时,向
    users/“$userid”/facebook/id
    写入已经太迟了,因为经过身份验证的用户现在是facebook用户,没有在那里写入的权限

    我错过什么了吗?关于如何补救这种情况有什么想法吗?

    类似的帖子如下: