fix(delete-user-data): move clearData to the v2 auth trigger - #2989
Open
IzaakGough wants to merge 4 commits into
Open
fix(delete-user-data): move clearData to the v2 auth trigger#2989IzaakGough wants to merge 4 commits into
IzaakGough wants to merge 4 commits into
Conversation
Kits reject gen1 endpoints, so the v1 auth.user().onDelete trigger made the kit undeployable. onUserDeleted emits a gcfv2 endpoint and carries the same user record. It is missing from the published firebase-functions type declarations, so a local module augmentation declares it until the types catch up.
Contributor
There was a problem hiding this comment.
Code Review
This pull request migrates the user deletion trigger from Firebase Functions v1 to v2 using onUserDeleted. It also introduces a temporary TypeScript declaration shim for onUserDeleted since it is currently missing from the published v2 types. The review feedback suggests adding defensive checks to ensure event.data and event.data.uid are defined before calling handleClear to prevent potential runtime errors.
The README still said clearData stays 1st gen. Also state why the onUserDeleted type is shimmed: it is beta and internal upstream, not a missing declaration that will appear on its own.
…record The Auth event only carries data when the payload envelope is present, so reading uid off it directly threw a TypeError. Log and skip instead. Adds the first test over the trigger itself: it pins the gen2 endpoint, which is what the deploy rejects if clearData regresses to gen1.
IzaakGough
marked this pull request as ready for review
August 28, 2026 16:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
clearDatausedfunctionsV1.auth.user().onDelete, and the CLI rejects any 1st gen endpoint in a kit (checkKitForGen1), sodelete-user-datacould not deploy as a kit at all.What changed
clearDatanow usesonUserDeletedfromfirebase-functions/v2/identity, a gen2 trigger ongoogle.firebase.auth.user.v2.deleted. The event only carriesdatawhen the payload envelope is present, so the handler logs and skips instead of throwing. The README still claimedclearDatastays 1st gen; fixed.That export is
@beta @internalupstream and stripped from the published types, so importing it fails withTS2305.src/identity-shim.d.tsdeclares it locally, andfirebase-functionsmust stay pinned exactly.How it was verified
Typecheck clean, 87 tests passing. New
tests/index.test.tscovers the trigger, which nothing did before: it fails if the endpoint regresses to 1st gen, and if the guard is removed.Deployed the changes in this PR to a real project and tested them end to end, and the trigger works.
Decision needed
onUserDeletedis beta and internal upstream, so it carries no stability guarantee and can change in a patch release. Land this as a stopgap, or escalate the missing GA gen2 Auth trigger?