带有Firebase的Angular无法访问数据 [英] Angular with Firebase can't access data

查看:63
本文介绍了带有Firebase的Angular无法访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Angular中有一个非常简单的应用,应该读取一个小的Firebase数据库...

I have a very simple app in Angular, that should read a small Firebase database...

很简单:

import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {
courses: any[];

constructor(db: AngularFireDatabase) {
db.list('/courses/IlZ5lAPfQDmWAf52hAI4')
  .valueChanges().subscribe(courses => {
    this.courses = courses;
    console.log(this.courses);
    });
  }
}

出于测试目的,不应对Firebase进行身份验证,换句话说,任何人都可以阅读它.

As it's for tests purpose, there should be no authentication to Firebase, in other words, anyone could read it.

规则设置为:

service cloud.firestore {
match /{multi_path=*} {
match /{multi_path=**} {
  allow read, write
    }
  }
}

我应该提到,在Firebase模拟器中,我可以列出/courses/IlZ5lAPfQDmWAf52hAI4文档.

I should mention that in the Firebase simulator, I can list the/courses/IlZ5lAPfQDmWAf52hAI4 document.

但是我一直收到没有权限的错误,例如:RROR错误:/courses/IlZ5lAPfQDmWAf52hAI4中的Permission_denied:客户端没有访问所需数据的权限.

But I keep getting the error of not having the permission, e.g.: RROR Error: permission_denied at /courses/IlZ5lAPfQDmWAf52hAI4: Client doesn't have permission to access the desired data.

我不知道发生了什么...应该很简单.

I can't figure out what's going on... Should be simple..

谢谢

推荐答案

您正在代码上使用 Firebase实时数据库,但是您提供了 Cloud Firestore 规则.
您应该使用实时数据库或Cloud Firestore.转到您的Firebase控制台,在开发/数据库"部分下,您可以在它们之间进行切换. 因此,请选择要使用的选项,并相应地提供其规则.
注意 -当前,您正在代码中使用Realtime数据库,因此,如果要使用Cloud Firestore,则必须在模块中更改导入并使用其他对象.您应该在官方文件中了解更多相关信息.

You are using Firebase Real-Time database on your code, But you provide a Cloud Firestore rules.
You should either use Real-time database or Cloud Firestore. Go to your firebase console and under the section of Develop/Database you can switch between them. So, make your choice which one you want to use and provide its rules accordingly.
NOTE - currently you are using the Realtime database in your code, so if you are gonna use the cloud firestore, you have to change your imports in the module and use different objects. you should read more about it in the official documents.

这篇关于带有Firebase的Angular无法访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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