0
votes

I'm using the Meteor useraccounts package and have setup some custom fields

AccountsTemplates.addFields([
    {
        _id: 'email',
        type: 'email',
        required: true,
        displayName: "email",
        re: /.+@(.+){2,}\.(.+){2,}/,
        errStr: 'Invalid email'
    },
    {
        _id: 'firstName',
        type: 'text',
        displayName: "First Name",
        required: true
    },
    {
        _id: 'lastName',
        type: 'text',
        displayName: "Last Name",
        required: true
    },
    pwd
]);

I'm trying to access the data on user sign up, IE Accounts.onCreateUser function but noting is working, trying to save the first and last name under profile.

// Name
options.profile.firstName = this.firstName;
options.profile.lastName = this.lastName;
user.profile = options.profile; 
1
Did you manage to get it to work? - Sceptic

1 Answers

0
votes

At this time you can't add extra fields to the default useraccounts package. So you will have to use your own custom form.

You can use the following code on server to set profile attributes on user creation.

Accounts.onCreateUser(function(options, user){
    var customProfile = new Object();

    customProfile.firstName= '';
    customProfile.lastName= '';

    user.profile = customProfile;
    return user;
});

Call the following function to create a user: http://docs.meteor.com/#accounts_createuser

Afterwards you can access and set those attributes using.

currentUser.profile.firstName
currentUser.profile.lastName