mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-13 16:22:59 +10:00
"deleteUser" Firebase cloud function: added deletion of user folder from Storage, added extra checks on IDs not being empty string
This commit is contained in:
@ -20,6 +20,10 @@ const deleteUserFunctionHandler = async (_, { auth }) => {
|
||||
|
||||
try {
|
||||
const userId = auth.uid;
|
||||
if (!userId) {
|
||||
throw new Error("Could not retrieve the user's unique ID.");
|
||||
}
|
||||
|
||||
const updates = {};
|
||||
|
||||
const userResumesDataSnapshot = await admin
|
||||
@ -31,7 +35,9 @@ const deleteUserFunctionHandler = async (_, { auth }) => {
|
||||
const userResumes = userResumesDataSnapshot.val();
|
||||
if (userResumes) {
|
||||
Object.keys(userResumes).forEach(async (resumeId) => {
|
||||
updates[`resumes/${resumeId}`] = null;
|
||||
if (resumeId) {
|
||||
updates[`resumes/${resumeId}`] = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -48,6 +54,11 @@ const deleteUserFunctionHandler = async (_, { auth }) => {
|
||||
await admin.database().ref().update(updates);
|
||||
}
|
||||
|
||||
const storageUserFolderPath = `users/${userId}/`;
|
||||
await admin.storage().bucket().deleteFiles({
|
||||
prefix: storageUserFolderPath,
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
throw new functions.https.HttpsError('internal', error.message);
|
||||
|
||||
Reference in New Issue
Block a user