使用 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?

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

问题描述

除非我在 auth 回调中访问 firebase 用户,否则该对象添加了 $$conf 以防止我创建用户配置文件的副本以移动到新位置.有什么办法可以解决吗?

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

用户对象注销:

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

即使我只是获取 user.uid 值,我仍然收到错误:

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.

任何想法将不胜感激.

推荐答案

制作同步对象的副本非常奇怪.根据定义,副本要么复制所有同步方法,要么立即陈旧过时.更有可能的是,您希望将用户 ID 存储在团队"路径中并引用实际数据,以使其始终保持最新.

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.

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

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天全站免登陆