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?

∥☆過路亽.° 提交于 2020-01-17 01:22:08

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/27166520/when-working-with-a-copy-of-a-user-in-firebase-conf-is-added-to-the-object-so

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!