Skip to content

🐛 [firebase_messaging] Always getting cloud_firestore/permission-denied with onBackgroundMessage isolate #10676

@ASE55471

Description

@ASE55471

Bug report

Describe the bug
I am tring to listening data changes from firestore in onBackgroundMessage. But when isolate start from terminated state, It always throw:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does n
ot have permission to execute the specified operation.
E/flutter (19800): #0      EventChannelExtension.receiveGuardedBroadcastStream (package:_flutterfire_internals/src/exception.dart:67:43)        
E/flutter (19800): #1      MethodChannelQuery.snapshots.<anonymous closure> (package:cloud_firestore_platform_interface/src/method_channel/metho
d_channel_query.dart:154:18)

But if i listening in background state, it works fine.

Steps to reproduce

Steps to reproduce the behavior:

  1. Put a firestore data listener in onBackgroundMessage
  2. Terminate application
  3. Send fcm to device
  4. Isolate start from Terminated state, And listener always get permission-denied

Expected behavior

I should be able to successfully getting data from firestore, Because i run exactly same code in both background and Terminated state, But it only works in background state.

Sample project

@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(
    RemoteMessage remoteMessage) async {
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  FirebaseFirestore.instance.collection("user").doc(id).snapshots()
}

Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[√] Flutter (Channel stable, 3.3.7, on Microsoft Windows [Version 10.0.19045.2728], locale zh-TW)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.3)
[√] VS Code (version 1.76.2)
[√] Connected device (5 available)
[√] HTTP Host Availability


Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
 firebase_core: ^2.4.1
 firebase_auth: ^4.2.9
 cloud_firestore: ^4.3.1
 firebase_messaging: ^14.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    resolution: userThis was a user issue, e.g. invalid configuration or code.type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions