Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,24 @@ const exportDataBucket = userPrivacyPaths.exportDataUploadBucket;
// Triggered by a user deleting their account.
exports.clearData = functions.auth.user().onDelete((event) => {
const uid = event.data.uid;
const instanceId = event.data.instanceId;

const databasePromise = clearDatabaseData(uid);
const storagePromise = clearStorageData(uid);
const firestorePromise = clearFirestoreData(uid);

return Promise.all([databasePromise, firestorePromise, storagePromise])
const promises = [
databasePromise,
firestorePromise,
storagePromise
]

if (instanceId) {
const instanceIdPromise = clearInstanceId(instanceId);
promises.push(instanceIdPromise);
}

return Promise.all(promises)
.then(() => console.log(`Successfully removed data for user #${uid}.`)
);
});
Expand Down Expand Up @@ -124,6 +136,19 @@ const clearFirestoreData = (uid) => {
return Promise.all(promises).then(() => uid);
};

// This function deletes the InstanceIDs that are used to track installation of
// Firebase apps. Deletion from caches and backups is not instantanteous.
//
// This function is called by the top-level `clearData` function, and requires
// an instanceID be passed in from the client.
//
// Returns a Promise
const instanceIdPromise = (instanceId) => {
return new Promise = (resolve, reject) => {
admin.instanceId().deleteInstanceId(instanceId);
};
};

// The `exportData` function reads and copys data from the RealTime Database,
// Storage, and Firestore. It waits to complete reads for all three, and then
// uploads a JSON file of the exported data to storage and returns a success
Expand Down Expand Up @@ -248,7 +273,7 @@ const exportStorageData = (uid) => {
let copyPromise = sourceFile.copy(destinationPath);
// Make copyPromise succeed even if it fails:
copyPromise = copyPromise.catch((err) =>
console.log('There is an error copying the promise, but keep going.')
console.log('There is an error copying, but I will keep going.')
);
// Add the copy task to the array of Promises
promises.push(copyPromise);
Expand Down