node.js – 多个Firebases实例

前端之家收集整理的这篇文章主要介绍了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/241248.html

猜你在找的Node.js相关文章