firebasegoogle-cloud-platformfirebase-authenticationgoogle-cloud-functions

How to remove user data with Firebase Functions V2?


I'm working with Firebase and want to delete all associated user data from Cloud Firestore and Cloud Storage when a user is deleted from Firebase Authentication. I need to achieve this using Firebase Functions v2.

With Cloud Functions v1, I used the following code:

const functions = require('firebase-functions/v1');

exports.deleteUserData = functions.auth.user().onDelete((user) => {...});

But right now, I am using Node 22, and v1 functions can't be used. Is there any similar method that does the same thing?


Solution

  • Currently, according to this issue, you can't use gen1 functions with the node 22 runtime:

    https://github.com/firebase/firebase-functions/issues/1653

    And, according to the documentation, you can't use non-blocking auth triggers on gen2:

    Note: Cloud Functions for Firebase (2nd gen) does not provide support for the events and triggers described in this guide. Because 1st gen and 2nd gen functions can coexist side-by-side in the same source file, you can still develop and deploy this functionality together with 2nd gen functions.

    So, all this means you can't use node 22 to run auth triggers that require gen1.

    If you want to run your auth trigger, you should back down to node 20 for now, until node 22 is out of "preview" and fully available.