Vit*_*sky 2 javascript firebase firebase-realtime-database angular6 firebase-security-rules
我只想将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.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)
Run Code Online (Sandbox Code Playgroud)
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,
]
Run Code Online (Sandbox Code Playgroud)
app.component.ts
export class AppComponent implements OnInit {
courses: Observable<any>;
constructor(private _db: AngularFireDatabase) {}
ngOnInit() {
this.courses = this._db.list('/courses').valueChanges();
}
}
Run Code Online (Sandbox Code Playgroud)
刚安装
npm install firebase angularfire2 --save
Run Code Online (Sandbox Code Playgroud)
没有帮助
npm install firebase-tools --save
firebase login
firebase init
Run Code Online (Sandbox Code Playgroud)
也没有帮助
文件database.rules.json
{
"rules": {
".read": "true",
".write": "true"
}
}
Run Code Online (Sandbox Code Playgroud)
console.firebase.google.com网站上的“规则”标签
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
请告诉我如何在Angular 6中正确安装Firebase
您已经为Cloud Firestore数据库设置了安全规则。但是您的代码正在尝试从Firebase实时数据库中读取。这两个数据库是完全分开的,并且使用不同的安全规则来控制访问。
要允许/courses对实时数据库中的节点进行读/写访问,请使用实时数据库的安全规则并使用:
{
"rules": {
"courses": {
".read": true,
".write": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2880 次 |
| 最近记录: |