Reputation: 109
I just want to install the firbase as database, but contantly getting this error:
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();
}
}
Just installed by
npm install firebase angularfire2 --save
didn't help
npm install firebase-tools --save
firebase login
firebase init
didn't help too
file database.rules.json
{
"rules": {
".read": "true",
".write": "true"
}
}
tab 'rules' on console.firebase.google.com site
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Please tell me how to install correctly the firebase in Angular 6
Upvotes: 2
Views: 7672
Reputation: 547
In Firebase auth there is a great method which allows users to sign anonymusly before they actually sign in.
First include the script for auth module after firebase script like this:
<!-- 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>
Then in your js or script use this code:
firebase.auth().signInAnonymously();
Upvotes: 0
Reputation: 11
Typically, this error appears after you write the "Firebase deploy" command in the console. If this is some kind of training project, then just manually change the security rules to the states of "read: true" and "write: true"
Upvotes: 0
Reputation: 599716
You've set the security rules for the Cloud Firestore database. But your code is trying to read from the Firebase Realtime Database. The two databases are completely separate, and use different security rules to control access.
To allow read/write access to your /courses
node in the realtime database, go the security rules for the realtime database and use:
{
"rules": {
"courses": {
".read": true,
".write": true
}
}
}
Upvotes: 8
Reputation: 109
On site console.firebase.google.com in the Database tab I selected Realtime Database instead of Cloud Firestore (beta) which was the default.
Upvotes: 4