简体   繁体   English

在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?

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. 除非我在auth回调中访问firebase用户,否则该对象将添加$$ conf,这将阻止我创建用户配置文件的副本以移至新位置。 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: 即使我只是获取user.uid值,我仍然会收到错误:

   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. 您更可能希望将用户ID存储在“团队”路径中,并引用实际数据,以便始终保持最新状态。

That said, to make a copy, just call toJSON to remove the $$ methods. 也就是说,要进行复制,只需调用JSON以删除$$方法。 Firebase provides a utility for this: Firebase为此提供了一个实用程序:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM