Angular Firebase权限错误,无法访问数据

时间:2018-07-10 16:12:01

标签: angular firebase firebase-realtime-database angularfire2

我正在尝试使用angular访问firebase,在我的服务中,我已经导入了该文件:

import { AngularFireDatabase , AngularFireList , AngularFireObject } from 'angularfire2/database';

我的构造函数和获取数据就像这样:

employees : AngularFireList<any>; // what comes from database
Employee : AngularFireObject<any>; // model

  constructor(public af:AngularFireDatabase) {
    this.employees = af.list('/employees') as AngularFireList<Employee>;
   }

   getEmployees(){
     return this.employees;
   }

在我的组件中,我这样调用getEmployees方法:

ngOnInit() {
    this.service.getEmployees().valueChanges().subscribe(employees => {
    this.employees = employees;
    console.log(this.employees);
  });
  }

当应用程序运行时,我在chrome控制台中遇到此错误:

ERROR Error: permission_denied at /employees: Client doesn't have permission to access the desired data. 

正如您在此处看到的那样,我具有Firebase的完全访问权限:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
} 

1 个答案:

答案 0 :(得分:0)

您编写的规则适用于 Firestore ,但是您的代码正在尝试访问实时数据库 ... Here is the link for the real-time database rules

要设置允许所有内容的实时数据库规则,请将其更改为:

{
  "rules": {
    ".read": true,
    ".write": false
  }
}