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

后端 未结 3 1657
一向
一向 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:27

    Well it wasn't so hard.. Here it stands in documentation: "The default create user function simply copies options.profile into the new user document. Calling onCreateUser overrides the default hook." - Accounts.onCreateUser

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-14 13:49

    Try this:

    Accounts.onCreateUser((options, user) => (Object.assign({}, user, options)));
    
    0 讨论(0)
提交回复
热议问题