NOTE: Sample Firebase Cloud Functions (Node.js).
const functions = require('firebase-functions');const admin = require('firebase-admin');const app = !admin.apps.length ? admin.initializeApp() : admin.app();const db = admin.firestore();exports.deleteBot = functions.https.onCall(async (data, context) => { const uid = context.auth.uid if (!context.auth) { throw new functions.https.HttpsError("unauthenticated", "Request had invalid credentials.") // throw new functions.https.HttpsError('failed-precondition', 'Credentials are missing') } const botId = data.botId if (!botId) { throw new functions.https.HttpsError('invalid-argument', 'Missing botId'); } const userRef = db.collection('user').doc(uid) const botRef = userRef.collection('bot').doc(botId) const batch = db.batch() batch.delete(botRef) const botMetaRef = userRef.collection('bot_meta').doc(botId) batch.delete(botMetaRef) await batch.commit(); return { uid: uid, botId: data.botId, status: 'ok' }});
NOTE: Call Cloud Functions From Web/JavaScript
References: