Collection hooks if failed

Hello ,
I am using collection hooks … Everything is going fine but i was wondering what i can do with the following case :

I have employee collection using the quick-form , after i submit the form, i use the collection hook ‘after.insert’ to create user account with 'Accounts.createUser ’ method … my question is what about if the collection hooks failed to create account ( ie : the email address has been used before or what ever ) , is it gonna revert the previous insertion of the employee record, if not … then i think this a big problem … your advice guys

Try this. you can use option callback to check if it error or not. if it error just remove current Employee doc.

Employee.after.insert((userId, doc)=>{
      username: 'user',
      email: '',
    }, function(err){

Thank you
got it :slight_smile: