Firebase permission-denied

前端 未结 4 1470
Happy的楠姐
Happy的楠姐 2021-02-20 08:59

I\'m a newbie in firebase.

How do I get through this below rule?

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document         


        
相关标签:
4条回答
  • 2021-02-20 09:28

    I was able to solve the problem by switching from Cloud Firestore to Realtime Database, and then changing the rule. (After I've changed this, there was no more error showing!)

    0 讨论(0)
  • 2021-02-20 09:32

    You should check in your Angular NgModule and components if you are using "Realtime Database" or "Cloud Firestore". See diferences using "angularfire2":

    REALTIME DATABASE

    @NgModule({
    ...
    imports: [
        AngularFireDatabaseModule,
        ...
    ],
    providers: [
    AngularFireDatabase,
    ...
    ]
    })
    
    
    @Component({...})
    export class FirestoreComponent{
       constructor(private realtimeDb:AngularFireDatabase, ...) {
           this.locations = realtimeDb.list('locations').valueChanges();
         }
    ...
    }
    

    CLOUD FIRESTORE

    @NgModule({
        ...
        imports: [
           AngularFirestoreModule,
           ...
        ]
    })
    
    @Component({...})
    export class FirestoreComponent{
       constructor(private firestore:AngularFirestore, ...) {
           this.locations = firestore.collection('locations').valueChanges();
         }
    ...
    }
    
    0 讨论(0)
  • 2021-02-20 09:44

    For others struggling with this problem, the proper solution is to change the false in

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

    To true while testing. Don't forget to add additional security when going live with your project!

    0 讨论(0)
  • 2021-02-20 09:44

    Because your method query the Firebase not Cloud Firestore so you should use this method :

    FirebaseFirestore db = FirebaseFirestore.getInstance();
        db.collection("YourCollectionName").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Log.d(TAG, document.getId() + " => " + document.getData());
                    }
                } else {
                    Log.w(TAG, "Error getting documents.", task.getException());
                }
            }
        });
    

    dont forget this :

    implementation 'com.google.firebase:firebase-firestore:17.0.1'
    
    0 讨论(0)
提交回复
热议问题