Accounts.onCreateUser adding extra attributes while creating new users, good practices?

后端 未结 3 1656
一向
一向 2021-02-14 13:04

I\'m creating new user with Accounts.createUser() and it works normally if you are not doing anything fancy. But I want to add some other fields to new user that are not listed

3条回答
  •  攒了一身酷
    2021-02-14 13:40

    The best thing I found to this issue is:

    Accounts.onCreateUser(function(options, user) {
        // Use provided profile in options, or create an empty object
        user.profile = options.profile || {};
    
        // Assigns first and last names to the newly created user object
        user.profile.firstName = options.firstName;
        user.profile.lastName = options.lastName;
    
        // Returns the user object
        return user;`enter code here`
    });
    

    https://medium.com/all-about-meteorjs/extending-meteor-users-300a6cb8e17f

提交回复
热议问题