Skip to content

fix(delete-user-data): move clearData to the v2 auth trigger - #2989

Open
IzaakGough wants to merge 4 commits into
kitsfrom
fix/dud-v2-auth-trigger
Open

fix(delete-user-data): move clearData to the v2 auth trigger#2989
IzaakGough wants to merge 4 commits into
kitsfrom
fix/dud-v2-auth-trigger

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Aug 26, 2026

Copy link
Copy Markdown

What was broken

clearData used functionsV1.auth.user().onDelete, and the CLI rejects any 1st gen endpoint in a kit (checkKitForGen1), so delete-user-data could not deploy as a kit at all.

What changed

clearData now uses onUserDeleted from firebase-functions/v2/identity, a gen2 trigger on google.firebase.auth.user.v2.deleted. The event only carries data when the payload envelope is present, so the handler logs and skips instead of throwing. The README still claimed clearData stays 1st gen; fixed.

That export is @beta @internal upstream and stripped from the published types, so importing it fails with TS2305. src/identity-shim.d.ts declares it locally, and firebase-functions must stay pinned exactly.

How it was verified

Typecheck clean, 87 tests passing. New tests/index.test.ts covers 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

onUserDeleted is 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?

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread kits/delete-user-data/src/index.ts Outdated
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
IzaakGough marked this pull request as ready for review August 28, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants