0

I'm writing a function that is triggered whenever a new user is created in Firebase. Debugging this function takes me ages because I deploy the cloud function for every single change. I use Firebase CLI to simulate other events in the database, but I can't figure out how to simulate a user creation correctly (with all the params).

To start the CLI I run:

firebase experimental:functions:shell

My function is:

exports.createTreeForNewUser = functions.auth.user().onCreate(event => {
    const user = event.data;
    console.log(user.uid);
    console.log(user.displayName);
    console.log(user.email);
    console.log(user.photoURL);
    console.log(user.metadata.creationTime);
    return null;
});

When I run the following command in the Firebase CLI:

createTreeForNewUser()

it prints undefined 4 times, followed by an exception because it can't extract creationTime from undefined. This behavior makes sense, but no matter what I tried, I couldn't figure out how to pass the event correctly (so that the function will be able to extract all the params I need).

The question is: How do I run the createTreeForNewUser with the event param set correctly?

Thanks! Slavik

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Slavik N
  • 4,705
  • 17
  • 23

1 Answers1

1

Pass the user object to the function:

createTreeForNewUser({
    uid: 'xxx',
    displayName: 'John',
    email: 'foo@bar.com',
    photoURL: 'https://...',
    metadata: {creationTime: 123}
})
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441