Javascript 在设置firebase之后,我得到以下错误:客户端没有';我没有访问所需数据的权限
我只想将firbase安装为数据库,但不断出现以下错误:Javascript 在设置firebase之后,我得到以下错误:客户端没有';我没有访问所需数据的权限,javascript,firebase,firebase-realtime-database,angular6,firebase-security,Javascript,Firebase,Firebase Realtime Database,Angular6,Firebase Security,我只想将firbase安装为数据库,但不断出现以下错误: ERROR Error: permission_denied at /courses: Client doesn't have permission to access the desired data. at errorForServerCode (index.cjs.js:647) at onComplete (index.cjs.js:9114) at Object.onComplete (index.cjs
ERROR Error: permission_denied at /courses: Client doesn't have permission to access the desired data.
at errorForServerCode (index.cjs.js:647)
at onComplete (index.cjs.js:9114)
at Object.onComplete (index.cjs.js:12681)
at index.cjs.js:11797
at PersistentConnection.push../node_modules/@firebase/database/dist/index.cjs.js.PersistentConnection.onDataMessage_ (index.cjs.js:12052)
at Connection.push../node_modules/@firebase/database/dist/index.cjs.js.Connection.onDataMessage_ (index.cjs.js:11337)
at Connection.push../node_modules/@firebase/database/dist/index.cjs.js.Connection.onPrimaryMessageReceived_ (index.cjs.js:11331)
at WebSocketConnection.onMessage (index.cjs.js:11232)
at WebSocketConnection.push../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.appendFrame_ (index.cjs.js:10837)
at WebSocketConnection.push../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.handleIncomingFrame (index.cjs.js:10887)
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { environment } from '../environments/environment';
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule,
]
app.component.ts
export class AppComponent implements OnInit {
courses: Observable<any>;
constructor(private _db: AngularFireDatabase) {}
ngOnInit() {
this.courses = this._db.list('/courses').valueChanges();
}
}
没用
npm install firebase-tools --save
firebase login
firebase init
也没用
文件database.rules.json
{
"rules": {
".read": "true",
".write": "true"
}
}
console.firebase.google.com网站上的“规则”选项卡
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
请告诉我如何在Angular 6中正确安装firebase,在site console.firebase.google.com的数据库选项卡中,我选择了实时数据库,而不是默认的Cloud Firestore(beta)。您已经为Cloud Firestore数据库设置了安全规则。但是您的代码正在尝试从Firebase实时数据库中读取。这两个数据库完全分开,并使用不同的安全规则来控制访问 要允许对实时数据库中的
/courses
节点进行读/写访问,请转到并使用:
通常,在控制台中编写“Firebase deploy”命令后会出现此错误。如果这是某种培训项目,那么只需手动将安全规则更改为“read:true”和“write:true”在Firebase auth中,有一种很好的方法允许用户在实际登录之前匿名登录 首先在firebase脚本之后包括auth模块的脚本,如下所示:
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.19.1/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.19.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.19.1/firebase-database.js"></script>
{
"rules": {
"courses": {
".read": true,
".write": true
}
}
}
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.19.1/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.19.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.19.1/firebase-database.js"></script>
firebase.auth().signInAnonymously();