无法在网络上对多个Firebase实时数据库进行身份验证 [英] Auth with multiple firebase realtime databases on web not working

查看:51
本文介绍了无法在网络上对多个Firebase实时数据库进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Firebase实时数据库.我已经设法从基于Web的客户端连接,读取和写入这两个文件.但是,我将重新检查我的安全规则并使其生效,因此,只有在使用

I have two Firebase realtime databases. I have managed to connect, read, and write to both of them from my web-based client. However, I am going back through my security rules and made it so you can only read/write if you are authenticated using

  "rules": {
    ".read": "auth.uid != null" ,
    ".write": "auth.uid != null" 
  }

但是,由于某种原因,我现在无法连接到数据库,它说权限被拒绝.我已使用Google在客户端上进行了身份验证,并且其他所有带有auth的功能都可以正常使用.例如,我能够打印出用户的uid和所有内容.这是我拥有(经过审查)的客户端代码.

However, for some reason I am now unable to connect to the database, it says that permission is denied. I am authenticated on the client using Google, and everything else with auth works as expected. For example, I'm able to print out the user's uid and everything. Here's the client side code I have (censored).

  var firebaseConfig = {
apiKey: "------------------",
authDomain: "-------------",
databaseURL: "-------------",
projectId: "-------",
};
// Initialize Firebase
var app = firebase.initializeApp(firebaseConfig, 'app2');

firebase.database(app).ref('boards').child(boardID).once('value', function(snapshot) {//I do stuff here})

错误:

Error: permission_denied at /boards/id: Client doesn't have permission to access the desired data.
    at util.ts:526
    at onComplete (SyncTree.ts:651)
    at Object.onComplete (Repo.ts:167)
    at PersistentConnection.ts:247
    at si.onDataMessage_ (PersistentConnection.ts:554)
    at ei.onDataMessage_ (Connection.ts:317)
    at ei.onPrimaryMessageReceived_ (Connection.ts:309)
    at $r.onMessage (Connection.ts:205)
    at $r.appendFrame_ (WebSocketConnection.ts:273)
    at $r.handleIncomingFrame (WebSocketConnection.ts:326)

这些是我正在使用的firebase脚本

And these are the firebase scripts I'm using

<script src="/__/firebase/7.6.1/firebase-app.js"></script>
<script src="/__/firebase/7.6.1/firebase-database.js"></script>
<script src="/__/firebase/7.8.1/firebase-auth.js"></script>
<script src="/__/firebase/init.js"></script>

这是一个已知的错误吗?我想念什么吗?谢谢.

Is this a known bug? Am I missing something? Thanks.

推荐答案

我通过从

<script src="/__/firebase/7.6.1/firebase-app.js"></script>
<script src="/__/firebase/7.6.1/firebase-database.js"></script>
<script src="/__/firebase/7.8.1/firebase-auth.js"></script>
<script src="/__/firebase/init.js"></script>

  <script src="https://code.jquery.com/jquery-latest.min.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.9.0/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.9.0/firebase-database.js"></script>
  <script src="https://www.gstatic.com/firebasejs/7.9.0/firebase-auth.js"></script>

并从 var app = firebase.initializeApp(firebaseConfig,'app2');

这使第二个数据库成为默认数据库,现在一切正常.但是,如果有一次在客户端上需要两个数据库引用,这将再次成为问题,据我所知,除非Firebase开发人员发布补丁,否则无法解决.

This made the second database be the default database and now everything is working properly. However, if there is ever a time where both database references are required on the client, this will once again become a problem, and as far as I can tell cannot be fixed unless the Firebase developers release a patch.

这篇关于无法在网络上对多个Firebase实时数据库进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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