微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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 =>一个身份验证状态

原文地址:https://www.jb51.cc/nodejs/241248.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐