0

I want to get data from Firebase but I get this Error from App

Error [cloud_firestore/permission denied] the caller does not have permission to execute the specified operation

W/DynamiteModule(32609): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found. I/DynamiteModule(32609): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0 W/ProviderInstaller(32609): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0. W/System (32609): ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86 D/ApplicationLoaders(32609): ignored Vulkan layer search path /system/priv-app/PrebuiltGmsCore/lib/x86:/system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk!/lib/x86:/system/lib:/vendor/lib for namespace 0xeceec0d0 2 W/System (32609): ClassLoader referenced unknown path: /system/priv-app/PrebuiltGmsCore/lib/x86 V/NativeCrypto(32609): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 294 native methods... D/NetworkSecurityConfig(32609): No Network Security Config specified, using platform default I/ProviderInstaller(32609): Installed default security provider GmsCore_OpenSSL W/art (32609): Before Android 4.1, method double java.util.concurrent.ThreadLocalRandom.internalNextDouble(double, double) would have incorrectly overridden the package-private method in java.util.Random W/art (32609): Before Android 4.1, method int java.util.concurrent.ThreadLocalRandom.internalNextInt(int, int) would have incorrectly overridden the package-private method in java.util.Random W/art (32609): Before Android 4.1, method long java.util.concurrent.ThreadLocalRandom.internalNextLong(long, long) would have incorrectly overridden the package-private method in java.util.Random W/Firestore(32609): (24.4.0) [Firestore]: Listen for Query(target=Query(product order by name);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null} I/art (32609): Do partial code cache collection, code=13KB, data=30KB I/art (32609): After code cache collection, code=13KB, data=30KB I/art (32609): Increasing code cache capacity to 128KB W/Firestore(32609): (24.4.0) [Firestore]: Listen for Query(target=Query(product order by name);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null} W/Firestore(32609): (24.4.0) [WatchStream]: (831f7a9) Stream closed with status: Status{code=CANCELLED, description=Disconnecting idle stream. Timed out waiting for new targets., cause=null}.

this is my code

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:store/widgets/custonActionBar.dart';

class MainHome extends StatelessWidget {
  MainHome({super.key});

  final Stream<QuerySnapshot> _product =
      FirebaseFirestore.instance.collection('product').snapshots();
  @override
  Widget build(BuildContext context) {
    return Container(
        child: Stack(
      children: [
        StreamBuilder(
            stream: _product,
            builder:
                (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
              // if the connection has error
              if (snapshot.hasError) {
                return Center(child: Text("Error ${snapshot.error})"));
              }
              // if connection was Loading
              if (snapshot.connectionState == ConnectionState.waiting) {
                return const Center(
                  child: CircularProgressIndicator(),
                );
              }
              return Center(
                  child: Container(
                child: Text('ProductName : shoes'),
              ));
            }),
        custonActioBar("Home", "0")
      ],
    ));
  }
}

I check my connection from firebase its fine

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ali ma
  • 5
  • 2
  • Please search for the error message you get going forward, as this has been covered before: https://stackoverflow.com/search?q=%5Bgoogle-cloud-firestore%5D+Missing+or+insufficient+permissions, https://stackoverflow.com/search?q=%5Bgoogle-cloud-firestore%5D+cloud_firestore%2Fpermission+denied. If you think your case is not answered in any of those, post your security rules and show how your code satisfies those rules. – Frank van Puffelen Nov 20 '22 at 21:16

1 Answers1

1

the [cloud_firestore/permission-denied] means you need to set Firestore rules properly on your Firebase console.

try changing your rules to something like this:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
  • While this can be a good idea to get an idea for where the problem lies, these rules might not be appropriate. – seveneights Nov 20 '22 at 21:05
  • for a new created project, this works fine but I guess that the rules should be corrected from the Firestore service user, Thanks – Gwhyyy Nov 20 '22 at 21:07