onCreateUser - 2 questions

onCreateUser() is a server only method and can only be called once.

My two questions are:

  1. What if a package wants to make use of onCreateUser()? It can’t because if the app also uses it, one of the onCreateUser()s won’t be called. Is there another way to do something once a user signs up? I tried using the collection-hooks package with Meteor.users.before.insert..., but that didn’t work.

  2. Is there a simple way to tell on the client if a user has just signed up? I’d like to have an onCreateUser() event on the client too. The reason is that I’d like to send a sign-up event to google analytics on a successful signup.

I think this is a limitation of the current API and should be changed/improved in the future. Just use the hook, include the default functionality from Meteor inside your method (basically copying stuff into user.profile) and then you could write a simple API extension that would allow adding multiple hooks while still providing that default functionality.

Well, the client usually controls the signup process, right? If that’s the case for you then you know when you’ve just completed the signup and can send the event to GA.
Otherwise… you could set a flag on the user item that says “justSignedUp:true” and let the client remove it once the event is sent to GA and you don’t need it any more?

The client does do signup, but there are all these different packages involved doing it, so it’s not so easy to know when a user has completed a sign up. The flag thing would work. Maybe I’ll do that.

You could use an ugly hack to monkey patch onCreateUser to do your stuff first to modify the user and options objects and then pass it along to the original function.