node.js – 多个Firebases实例

当我尝试制作一个以上的新Firebase(url)时,我遇到了问题.实例.

例如:

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 null,就是它..不再.

所以,这意味着它永远不会从v1.auth()调用回调函数;它忽略了它,看起来它被v2.auth()覆盖;即使它们是不同的Firebase实例,它也会干扰其他所有内容,例如,v1.child(“path”).on(“value”,function(snapshot){});和v2.child(“path”).on(“value”,function(snapshot){});发生这种情况时不起作用.

解决方法

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

this page in the Firebase documentation开始:

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身份验证的工作方式可能不同,但我对此表示怀疑.

更新

您提供了another page in the Firebase documentation的报价:

It is not possible to authenticate with multiple credentials to the same Firebase simultaneously,even if we call .auth on different Firebase references. Authentication state is global and applies to all references to the Firebase. However,it is possible to create references to two or more different Firebases and authenticate to those independently.

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

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...