I write a function witch cleanup all user data (collections, sub-collections, and images) from Cloud Firestore after he signs out from the account.
For this, I use the code from here.
My code:
'use strict';
const functions = require('firebase-functions');
const firebase_tools = require('firebase-tools');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
//const bucket = admin.storage().bucket("gs://movere-point.appspot.com/");
exports.recursiveDelete = functions.runWith({
timeoutSeconds: 540,
memory: '2GB'
})
.auth.user().onDelete((user) => {
// const path = data.path;
const path = "/Users/" + user.uid;
console.log(path);
return firebase_tools.firestore.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: ""
})
.then(() => {
return {
path: path
};
});
});
I remove a user from the Firebase console, and in the log of Function, I get the error:
Error
at new FirebaseError (/srv/node_modules/firebase-tools/lib/error.js:9:18)
at module.exports (/srv/node_modules/firebase-tools/lib/responseToError.js:38:12)
at Request._callback (/srv/node_modules/firebase-tools/lib/api.js:39:35)
at Request.self.callback (/srv/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/srv/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/srv/node_modules/request/request.js:1083:12)
Help solve the problem with the removal of all user data after the user leaves the program