Search code examples
androidflutterfirebasefirebase-storagefirebase-app-check

Why is Firebase Storage expecting an App Token?


I'm creating an app using Firebase Authentication, Realtime Database, Firestore and Storage. I am not using AppCheck. I only just added Storage in, but now I get this error spammed at me:

W/StorageUtil( 9338): Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: No AppCheckProvider installed.

This is the only new code I've added (some irrelevant methods removed):

class AccountSettingsPageState extends State<AccountSettingsPage>{
Unit8List? _image;

  void selectAndSaveImage() async {
    //Pick image file using method below this
    Uint8List img = await pickImage(ImageSource.gallery);
    setState(() {
      _image = img;
    });

    //Save in Firebase, file name = user's uid
    Reference ref = storageRef.child('Profile Pictures').child(auth.currentUser!.uid);
    ref.putData(_image!);
  }

  pickImage(ImageSource source) async {
    final ImagePicker imagePicker = ImagePicker();
    XFile? file = await imagePicker.pickImage(source: source);

    if(file != null){
      return await file.readAsBytes();
    } else{
      debugPrint('no image is selected');
    }
  }
}

class DatabaseHandler{

//called on startup after first downloadUsersData
  void getAllUserProfilePics() async {
    //Save profile image as Uint8List if they have one
    for (UserData user in allUsersList){
      final profilePicRef = storageRef.child(user.uid);

      // List all items at the given path
        ListResult result = await profilePicRef.listAll();

      // Check if there are any items in the list (i.e if the user has a profile picture)
      if (result.items.isNotEmpty) {
        //Save the image
        final Uint8List? image = await profilePicRef.getData(oneMegabyte);
        user.profilePic = image;
      }
    }
  }

  void listenForProfilePicChanged() {
    final storageRef = FirebaseStorage.instance.ref();

    // Reference to the folder where user profile pictures are stored
    final profilePicsRef = storageRef.child('profile_pics');

    // Use asStream to convert the Future returned by listAll to a stream
    profilePicsRef.listAll().asStream().listen((ListResult result) {
      for (var itemRef in result.items) {
        // Get the UID from the item's name (assuming the UID is the name of the file)
        String uid = itemRef.name;

        // Find the corresponding UserData object in allUsersList
        UserData user = allUsersList.firstWhere(
          (userData) => userData.uid == uid
        );

        // Check if the user exists in the list
        if (user.uid.isNotEmpty) {
          // Download the new profile picture
          itemRef.getData(oneMegabyte).then((Uint8List? image) {
            // Update the user's profile picture in the UserData object
            user.profilePic = image;

          }).catchError((error) {
            debugPrint('Error downloading profile picture: $error');
          });
        }
      }
    });
  }
}



Solution

  • That's not an error. That's just a diagnostic warning, and you can tell because it starts with a "W". You can ignore it as long as everything is working the way you expect.

    If you don't like the fact that the log exists, file an issue with Firebase on the Android SDK repo, or modify and build the Storage SDK yourself so it works the way you want. You can see where the log is generated in the source code.