在Firebase中使用用户的副本时,会将$$ conf添加到对象中,因此我无法将用户复制到新位置? [英] When working with a copy of a user in firebase $$conf is added to the object so I can't copy the user to a new location?

查看:115
本文介绍了在Firebase中使用用户的副本时,会将$$ conf添加到对象中,因此我无法将用户复制到新位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除非我在身份验证回调中访问Firebase用户,否则该对象会添加$$ conf,这会阻止我创建用户配置文件的副本以移至新位置。有没有办法解决这个问题?

  //这个的任何变化似乎都不起作用,除了在auth回调函数中
var teamRef =新的Firebase('https://demo.firebaseio.com/teams/'+ teamName);
var teamList = $ firebase(teamRef.child('profiles'));
teamList。$ set(user.uid,user);

用户对象注销:

< pre $ e $ $$ conf $对象,$ id:simplelogin:107,$ priority:null,email:andrey@dsrp.tv,md5_hash:7130dfaebedd9ac16f5e5d73822b160c...} $$ conf:Object $ id:simplelogin:107$ priority:null

即使我只是抢到user.uid值我仍然得到错误:

 错误:Firebase.set失败:第一个参数包含一个无效的键$$ CONF)。键必须是非空字符串,不能包含。,#,$,/,[或]

这阻止了我死在我的轨道上。我目前正试图想办法从auth回调而不是在不同的位置做我需要做的事情。



任何想法将不胜感激。

解决方案

创建一个同步对象的副本是非常奇怪的。根据定义,复制将复制所有的同步方法,否则将立即陈旧和过期。更可能的是,您希望将用户标识存储在团队路径中,并引用实际数据,以便始终保持最新。



也就是说,复制,只需调用toJSON来删除$$方法。 Firebase为此提供了一个实用程序:

$ p $ var $ user $ $ firebase(...)。$ asObject();
var userCopy = $ firebaseUtils.toJSON(user);
... $ set(user.uid,userCopy);


Unless I am accessing a firebase user in an auth callback, the object has $$conf added to it which prevents me from creating a copy of a user profile to move to a new location. Is there any way around that?

//any variation of this doesn't seem to work except for in an auth callback
var teamRef = new Firebase('https://demo.firebaseio.com/teams/' + teamName);
var teamList = $firebase(teamRef.child('profiles'));
teamList.$set(user.uid, user);

The user object logs out to this:

e {$$conf: Object, $id: "simplelogin:107", $priority: null, email: "andrey@dsrp.tv", md5_hash: "7130dfaebedd9ac16f5e5d73822b160c"…}$$conf: Object$id: "simplelogin:107"$priority: null

Even if I just grab the user.uid value I still get the error:

   Error: Firebase.set failed: First argument  contains an invalid key ($$conf).  Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

This has stopped me dead in my tracks. I'm currently trying to think of a way to do what I need to do from an auth callback instead of in a different location.

Any ideas would be much appreciated.

解决方案

It would be extremely odd to make a copy of a synchronized object. By definition, either the copy would duplicate all the synchronizing methods, or it would be immediately stale and out of date. More likely, you want to store the user ids in your "teams" path and reference the actual data so that it's always up to date.

That said, to make a copy, just call toJSON to remove the $$ methods. Firebase provides a utility for this:

var user = $firebase(...).$asObject();
var userCopy = $firebaseUtils.toJSON(user);
...$set(user.uid, userCopy);

这篇关于在Firebase中使用用户的副本时,会将$$ conf添加到对象中,因此我无法将用户复制到新位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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