Recommended way to initialize user object during registration

I know of at least 3 different ways to initialize fields in the Meteor users object: Accounts.onCreateUser, collection hooks (Meteor.users.after.insert), and with default/auto values in simpl-schema. All 3 seem to work fine (and in fact my app currently uses several at the same time for reasons unknown even to me) but I’m wondering if there is a recommended way. I need to add several new fields with default values, preferably on the server side.

I’m actually working on this right now. I’ve moved away from using collection hooks and Collection2 because anything you define there will happen automatically after any database operation, and it’s easy to forget it and end up very confused.

So I now use Accounts.onCreateUser, as well as a custom onInsert SimpleSchema field that plays the same role as default/auto values except I call it manually from within onCreateUser.

Thanks @sacha. That’s what I’ve discovered this evening. I was using simpl-schema to set defaults and autoValues and the fields were getting updated at wrong times. So I’ve moved back to onCreateUser and onLogin and things are much more obvious. Just a word of caution to anyone trying this: onLogin will get called when the user signs in and when the user verifies their email address and if the user refreshes a page. So if you have something like a lastLogin field then you need to check that info.type === "password" && info.methodName === "login" (where info is whatever you’ve called the argument to your function). You can also check for info.methodName === "verifyEmail" If you want to do something special when the user verifies their email address or type === "resume" if you wanted to do something special when the page is refreshed.