firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.65k stars 3.96k forks source link

firebase auth, firebase firestore: Insufficient permissions for accessing firestore on some queries, but working normally on others same rules for both #13398

Open krumpking opened 3 days ago

krumpking commented 3 days ago

Is there an existing issue for this?

Which plugins are affected?

Core, Auth, Database

Which platforms are affected?

Web

Description

Firebase firestore authentication works sometimes and sometimes returns insufficient permissions, all users who are login in are authenticated, see attached the firestore rules, a picture of different 'users' (in the app, the code to show the user profile is the same however) ![Screenshot 2024-09-25 at 10 42 56](https://github.co Screenshot 2024-09-25 at 11 09 50

Screenshot 2024-09-25 at 10 43 17 m/user-attachments/assets/bc192505-9757-4696-b8dc-2778083ff60b)

Reproducing the issue

Create a flutter firebase app with authentication, and connecting to firestore with rules that only allow authenticated users to access the firestore, and run it on web

Firebase Core version

3.3.0

Flutter Version

3.24.0

Relevant Log Output

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   packages/alpha/core/utils/logs.dart 27:7                                        logError
│ #1   packages/alpha/features/manage_profile/pages/upcoming_shifts_tab.dart 40:21     <fn>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Failed to fetch user shifts: [cloud_firestore/permission-denied] Missing or insufficient permissions.
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   packages/alpha/core/utils/logs.dart 27:7                                        logError
│ #1   packages/alpha/features/manage_profile/pages/previous_shifts_tab.dart 40:21     <fn>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Failed to fetch user shifts: [cloud_firestore/permission-denied] Missing or insufficient permissions.
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   packages/alpha/core/utils/logs.dart 27:7                                        logError
│ #1   packages/alpha/features/manage_profile/pages/feedback_tab.dart 35:21            <fn>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Failed to fetch user shifts: [cloud_firestore/permission-denied] Missing or insufficient permissions.
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0   packages/alpha/core/utils/logs.dart 27:7                                        logError
│ #1   packages/alpha/features/manage_profile/pages/notes_tab.dart 35:21               <fn>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ ⛔ Failed to fetch user notes: [cloud_firestore/permission-denied] Missing or insufficient permissions.

Flutter dependencies

name: alpha description: "A new Flutter project."

The following line prevents the package from being accidentally published to

pub.dev using flutter pub publish. This is preferred for private packages.

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment: sdk: ^3.5.0

dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.8 loader_overlay: ^4.0.1 firebase_core: ^3.3.0 shared_preferences: ^2.3.2 animated_introduction: ^1.0.4 firebase_auth: ^5.1.4 flutter_riverpod: ^2.5.1 get: ^4.6.6 loading_animation_widget: ^1.2.1 extended_phone_number_input: ^1.0.2 logger: ^2.4.0 lottie: ^3.1.2 animated_splash_screen: ^1.3.0 image_stack: ^2.1.1 cloud_firestore: ^5.2.1 sidebarx: ^0.17.1 cached_network_image: ^3.4.0 skeletonizer: ^1.4.2 file_picker: ^8.0.7 intl: ^0.19.0 firebase_storage: ^12.2.0 path: ^1.9.0 image_picker: ^1.1.2 csc_picker: ^0.2.7 open_filex: ^4.5.0 dio: ^5.7.0 path_provider: ^2.1.4 url_launcher: ^6.3.0 syncfusion_flutter_pdfviewer: ^26.2.13 json_annotation: ^4.9.0 tap_to_expand: ^0.7.2 tuple: ^2.0.2

dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^4.0.0 json_serializable: ^6.8.0 build_runner: ^2.4.9

flutter: uses-material-design: true assets:

Additional context and comments

No response

krumpking commented 3 days ago

Screenshot 2024-09-25 at 11.19.53 Screenshot 2024-09-25 at 11 19 27 Screenshot 2024-09-25 at 11 19 53 Same code, different user clicked, not errors

SelaseKay commented 3 days ago

Hi @krumpking , thanks for submitting this report. Which auth method are you using?

krumpking commented 3 days ago

Email and password

SelaseKay commented 3 days ago

Hi @krumpking , this error typically occurs when you're not authenticated. Could you please confirm that you're authenticated before attempting to fetch data from Firestore?

krumpking commented 3 days ago

Yes, I also attached another screenshot of the same code, on a different 'user' account, to the user it's different but the code is the same,

SelaseKay commented 3 days ago

I'm unable to reproduce this on my end. Can you try inspecting(printing) the uid of the current user(FirebaseAuth.instance.currentUser?.uid)? If the the value is null, it implies the user is not logged in.

krumpking commented 3 days ago

Okay, thank you, what would cause the user to log in and out? Like that?

SelaseKay commented 3 days ago

I'm quite certain the login session expires after some period of time.