Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
Firebase Function - finished with status code: 204

I have a firebase cloud function:

const admin = require('firebase-admin');
const firebase_tools = require('firebase-tools');
const functions = require('firebase-functions');

admin.initializeApp();


exports.deleteUser = functions
  .runWith({
    timeoutSeconds: 540,
    memory: '2GB'
  })
  .https.onCall((data, context) => {

  const userId = context.auth.uid;
  var promises = [];

  // DELETE DATA
  var paths = ['users/' + userId, 'messages/' + userId, 'chat/' + userId, 'like/' + userId];

  paths.forEach((path) => {
    promises.push(
      recursiveDelete(path).then(  () => {
          return 'success';
        }
      ).catch( (error) => {
        console.log('Error deleting user data: ', error);
      })
    );
  });

  // DELETE FILES
  const bucket = admin.storage().bucket();
  var image_paths = ["avatar/" + userId, "avatar2/" + userId, "avatar3/" + userId];
  image_paths.forEach((path) => {
    promises.push(
      bucket.file(path).delete().then(  () => {
            return 'success';
          }
         ).catch( (error) => {
          console.log('Error deleting user data: ', error);
        })
      );
    });

  // DELETE USER
  promises.push(
    admin.auth().deleteUser(userId)
    .then( () => {
      console.log('Successfully deleted user');
      return true;
    })
    .catch((error) => {
      console.log('Error deleting user:', error);
    })
  );

  return Promise.all(promises).then(() => {
    return true;
  }).catch(er => {
      console.error('...', er);
  });
});




function recursiveDelete(path, context) {
    return firebase_tools.firestore
    .delete(path, {
      project: process.env.GCLOUD_PROJECT,
      recursive: true,
      yes: true,
      token: functions.config().fb.token
    })
    .then(() => {

      return {
        path: path
      }
    }).catch( (error) => {
      console.log('error: ', error);
      return error;
    });
  }
  // [END recursive_delete_function]

Im trying to run this function locally from a javascript file:

function deleteAccount(userId) {
  fetch(
    `https://us-central1-myappname.cloudfunctions.net/deleteUser/${userId}`,
    { method: "DELETE" }
  );
}

But im getting a:

deleteUser Function execution took 1952 ms, finished with status code: 204

Here is my cloud function URL from firebase:

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Posting an answer based on my comment and above community members comments for visibility.

Based on the comment from stf_F it is a good idea to use callable functions as it remembers the state, and you don't have to pass any UID to delete the user. Or you can delcare it also as mentioned in this document.


const text = data.text;

// Authentication / user information is automatically added to the
request.

const uid = context.auth.uid;

const name = context.auth.token.name || null;

const picture = context.auth.token.picture || null;

const email = context.auth.token.email || null;index.js  

And you can check how to delete using callable from the following document.

However, if you prefer using fetch and if you want to know how to get the data in JSON and how to save it in HTML. You can check this article. You can use the following example regarding how to structure your fetch

    fetch(functionEndpoint)
        .then(res => res.json()) 
        .then(function(data) {
                      /** DO STUFF WITH YOUR DATA **/
                  }).catch(function(error) {
                      console.log("Err is:" + err);
                  });

And Below example how to use get and fetch the info you need.

    document.getElementById("output").innerHTML =
        JSON.stringify(data, null, 2); } 

Please don't forget to specify the output in your HTML page

<pre id="output"> </pre>

And you can check the following document of how to parse the received JSON data and extract UID for example.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!