Auth event v1 compat - #1953
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces v1-compatible getters (user and context) to the v2 onUserCreated and onUserDeleted Identity triggers, enabling developers to use v1-style destructuring. It also adds corresponding unit tests to verify this compatibility. A critical runtime issue was identified where calling the trigger's .run() method in unit tests with a vanilla mock event will crash if destructuring is used, because .run is not wrapped with addV1Compat. It is recommended to wrap func.run to apply the compatibility layer.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds backward-compatible v1 getters (context and user) to the v2 Firebase Authentication triggers (onUserCreated and onUserDeleted) by wrapping the events using addV1Compat in both the main trigger execution and the .run() method. The feedback suggests adding a defensive check for the event parameter in func.run to prevent potential TypeErrors when developers call .run() with nullish values in unit tests.
relnote: none
Description
Adds
V1Compatdestructuring support to 2nd-Gen Firebase Authentication triggers (onUserCreatedandonUserDeleted), bringing Auth to full feature and type parity withfirestore,pubsub,storage,database, andremoteConfig.Key changes:
addV1Compat: Attachesuser(returningevent.data) andcontext(returninggetV1AuthContext(event)) via non-enumerable, memoized getters with zero performance/allocation overhead for standard v2 callers.getV1AuthContext): Maps legacyEventContextproperties:eventType: Translates v2 CloudEvent types to"providers/firebase.auth/eventTypes/user.create"and"user.delete".resource: Setsservice: "firebaseauth.googleapis.com"and normalizesnameby stripping//identitytoolkit.googleapis.com/.params: {},eventId,timestamp.(event: AuthEvent<User> & V1Compat<"user", User>)and(event: AuthEvent<User>)to ensure user test suites passing vanilla POJOCloudEventmocks to.run()compile without type friction.IDENTITY_TOOLKIT_SOURCE_PREFIX,FIREBASE_AUTH_SERVICE,USER_CREATED_EVENT,USER_DELETED_EVENT).Scenarios Tested
spec/v2/providers/identity.spec.ts):v1-compatible getters(event.userand all fields ofevent.context).onUserCreated(({ user, context }) => ...)..run().npm test).onUserCreated(({ user, context }) => ...)to test projectvarun-test-project-auth.user.uid,user.email,context.eventId,context.eventType, andcontext.resourcewere captured and logged correctly.