1

Firebase subcollection will not be deleted.

I tried to delete the subcollection from (chat_list_page.dart) to (deleMyChatList) to (recursiveDelete), but it was not deleted.

(UnhandledException: [firebase_functions/invalid-argument] INVALID ARGUMENT) appears.

index.js

exports.recursiveDelete = functions
  .region("asia-northeast3")
    .runWith({
  timeoutSeconds: 540,
  memory: '2GB'
})
.https.onCall(async (data, context) => {
  // Only allow admin users to execute this function.
  if (!(context.auth && context.auth.token && context.auth.token.admin)) {
    throw new functions.https.HttpsError(
      'permission-denied',
      'Must be an administrative user to initiate delete.'
    );
  }

  const path = data.path;
  console.log(
    `User ${context.auth.uid} has requested to delete path ${path}`
  );

  await firebase_tools.firestore
    .delete(path, {
      project: process.env.GCLOUD_PROJECT,
      recursive: true,
      yes: true,
      token: functions.config().fb.token
    });

  return {
    path: path
  };
});

chat_list_page.dart:

Future<HttpsCallable> deleMyChatList({required String path,}) async {
  var deleteFn = FirebaseFunctions.instance.httpsCallable('recursiveDelete');
  deleteFn.call();
  return deleteFn;
}

onDismissed: (_) {
    setState(() {
      myProducts.removeAt(index);
      // deleMyChatList(key3);
      deleMyChatList(path : "/chats/peLVfT2AjARVL1pRDBla0gj8i5t2_1656195670264_kakao/");
    });
  },
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
kimdongho
  • 11
  • 1
  • 2
    Does this answer your question? [Flutter Firebase delete subcollections not working](https://stackoverflow.com/questions/62104658/flutter-firebase-delete-subcollections-not-working) – Andrés Jul 08 '22 at 18:43

0 Answers0