firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 925 forks source link

Context passed to emulated auth.onCreate is not a valid EventContext #2752

Open fnberta opened 3 years ago

fnberta commented 3 years ago

[REQUIRED] Environment info

firebase-tools:8.14.1

Platform:macOS

[REQUIRED] Test case

 functions
  .auth.user()
  .onCreate(userRecord, context) => { 
    console.log(context) 
  }

[REQUIRED] Steps to reproduce

Include the above snippet as a cloud function and create a new user. You'll see that the context is not a valid EventContext.

[REQUIRED] Expected behavior

I would expect context to contain all properties specified in EventContext.

[REQUIRED] Actual behavior

context is missing e.g. the eventId and the timestamp. See the log output:

{
  eventType: 'google.firebase.auth.user.create',
  resource: { service: 'firebaseauth.googleapis.com', name: undefined },
  params: {}
}
samtstern commented 3 years ago

@fnberta thank you for reporting this! Seems like a bug to me.

malcolmdeck commented 3 years ago

I've filed b/172262957 to track this internally

abeisgoat commented 3 years ago

Digging into this, seems we're not passing a proper context. Will report back.

lloydrichards commented 3 years ago

Has this been resolved? I've run into the exact problem while trying to unit test my Functions. The context coming from the emulator is missing .eventId and .timestamp

lloydrichards commented 3 years ago

After some more testing, I also noticed that it is giving the right context when I run a firebase triggered function, but not when I run an Auth triggered function.