I am trying to create a cloud function with firebase functions to detect if the user emailVerified prop changes. This is what I currently have in my index.js in functions folder:
exports.emailVerifiedChange = functions.auth.user().onCreate((user)=> {
if(user.emailVerified) {
admin.firestore().collection(`users`).doc(user.uid).create({
created: new Date(),
uid: user.uid,
name: user.displayName,
searchName: user.displayName.toLowerCase(),
userInfo: {
profilePic: '',
phoneNumber: '',
email: user.email
},
provider: false
})
}
})
In the log, this function is called when a user is created but the user collection is not created. Any idea? I'm new to functions so not sure why its not working.