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