Is there a post createUser hook in meteor when using accounts-ui package?

后端 未结 6 1015
广开言路
广开言路 2020-12-03 06:58

Let\'s say I have a todo app, and I want to make sure that every user that registers has at least one todo to start with, something like \"First todo to cross off!\", how wo

6条回答
  •  抹茶落季
    2020-12-03 07:41

    I used the _.wrap method described above but wanted to include an additional suggestion. It's a good idea to call the original callback from your new custom callback. Meteor does some things on the callback that we don't want to miss.

    Modified code that worked like a champ for me:

    Accounts.createUser = _.wrap(Accounts.createUser, function(createUser) {
    
        // Store the original arguments
        var args = _.toArray(arguments).slice(1),
            user = args[0];
            origCallback = args[1];
    
        var newCallback = function(error) {
            // do my stuff
    
            origCallback.call(this, error);
        };
    
        createUser(user, newCallback);
    });
    

提交回复
热议问题