多个Firebase实例 [英] Multiple Firebases instances

查看:54
本文介绍了多个Firebase实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试制作多个 new Firebase(url); 实例时遇到问题.

I'm having a problem when I try to make more than one new Firebase(url); instance.

例如:

var token1 = "c.AdASdsAsds...";
var token2 = "c.dkasdEddss...";

var v1 = new Firebase('https://developer-api.nest.com');
v1.auth(token1,function(err){ 
    console.log("Connected 1 "+err);
},function(err){ console.log("Cancel 1: "+err); });

var v2 = new Firebase('https://developer-api.nest.com');
v2.auth(token2,function(err){ 
    console.log("Connected 2 "+err);
},function(err){ console.log("Cancel 2 "+err); });

控制台日志: 已连接2个空 ,仅此而已.

Console logs: Connected 2 null and that's it.. no more.

因此,这意味着它永远不会从 v1.auth();调用回调函数; 会忽略它,看起来它会被 v2.auth(); v1.child("path").on("value",function(snapshot){}); v2.child("path").on("value",function(snapshot){}); 在这种情况下将不起作用.

So, it means it never calls the callback function from v1.auth(); it ignores it, it looks like it becomes overridden by the v2.auth(); even though they are different Firebases instances, and it interferes everything else, for example, the v1.child("path").on("value",function(snapshot){}); and v2.child("path").on("value",function(snapshot){}); won't work when this happens.

推荐答案

您只能在使用Firebase身份验证的单个页面中进行一次身份验证.

You can only be authenticated once in a single page that uses Firebase authentication.

Firebase文档中的此页面:

对Firebase的所有引用共享相同的身份验证状态.因此,如果您两次调用new Firebase()并在其中之一上调用auth(),则它们都将通过身份验证.

All references to a Firebase share the same authentication status. So if you call new Firebase() twice and call auth() on one of them, they will both be authenticated.

当然可能是nest-api身份验证的工作方式不同,但我对此表示怀疑.

It could of course be that the nest-api authentication works differently, but I doubt it.

您提供了 Firebase文档中另一页上的报价:

即使我们在不同的Firebase引用上调用.auth,也无法同时使用多个凭据对同一Firebase进行身份验证.身份验证状态是全局的,适用于对Firebase的所有引用.但是,可以创建对两个或多个不同Firebase的引用并对其进行独立身份验证.

但是在您的代码中,两个连接都指向同一个Firebase: https://developer-api.nest.com .一种Firebase =>一种身份验证状态.

But in your code both connections are to the same Firebase: https://developer-api.nest.com. One Firebase => one authentication state.

这篇关于多个Firebase实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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