I'm trying to create a new collection 'profile' when Accounts.onCreateUser is run however I'm getting a ReferenceError: Profile is not defined. I assume it's a load order problem. If I move the schema file into a lib folder it works however I'm trying to use the file structure that is now recommended on the Meteor site.
Can some please let me know what I'm missing. I'm new to import and export to so it might be related to that.
Path: imports/profile/profile.js
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
SimpleSchema.debug = true;
Profile = new Mongo.Collection("profile");
Profile.allow({
insert: function(userId, doc) {
return !!userId;
},
update: function(userId, doc) {
return !!userId;
},
remove: function(userId, doc) {
return !!userId;
}
});
var Schemas = {};
Schemas.Profile = new SimpleSchema({
userId: {
type: String,
optional: true
},
firstName: {
type: String,
optional: false,
},
familyName: {
type: String,
optional: false
},
});
Profile.attachSchema(Schemas.Profile);
Path: server/userRegistration/createUser.js
Meteor.startup(function () {
console.log('Running server startup code...');
Accounts.onCreateUser(function (options, user) {
if (options.profile && options.profile.roles) {
Roles.setRolesOnUserObj(user, options.profile.roles);
Profile.insert({
userId: user._id,
firstName: options.profile.firstName,
familyName: options.profile.familyName,
});
}
if (options.profile) {
// include the user profile
user.profile = options.profile;
}
return user;
});
});