RESOLVED: Trigger event when new user is created - how to do?

I am using accounts-password and accounts-ui. How can I add an entry to a collection automatically when a new account is created?

This event is called before the new user is created: http://docs.meteor.com/#/full/accounts_oncreateuser

Perhaps that will help.

I want to add a user name to the collection…

Yes, you’ll get the username as part of the user object passed into the function.

so, i could do the following:

Accounts.onCreateUser(function(options, user) {user.profile = options.profile;
// add my code to add record to collection here

  return user;
});

Will this trigger from isClient? Or do I need to put it in a helper?

I have added the following to my Meter.isServer:

  Accounts.onCreateUser(function(options, user) {user.profile = options.profile;
                                         // add my code to add record to collection here
                                         console.log("USER: "+user.username);
                                         console.log("USER: "+user.profile);
                                         console.log("USER: "+user.userId);
                                         return user;
                                        });

Each part comes back as undefined…

I was hoping to get a userId…

Well, for one the ID would be user._id. But if it’s not set at this point you could probably do user._id = Random.id().

How about matb33:collection-hooks? I use the following to add a document to a Targets collection whenever a new account is created.

Meteor.users.after.insert(function () {
    var targetsId = Targets.insert({userId: this._id});
    return {
        _id: targetsId
    };
});

That did it:) Thanks.