2
我试图创建一个新的集合'配置文件'时运行Accounts.onCreateUser但是我得到一个ReferenceError:配置文件未定义。我认为这是一个加载顺序问题。如果我将模式文件移动到一个lib文件夹中,它可以工作,但我试图使用Meteor网站上现在推荐的文件结构。ReferenceError:没有定义
有些请让我知道我失踪。我是新进口和出口,所以它可能与此有关。
路径: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);
路径: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;
});
});
我现在越来越'异常而调用方法“ATCreateUserServer”类型错误:无法读取的undefined' – bp123
财产“插入”不,他需要导出配置文件从'profile.js'以及? –
@MichelFloyd你是完全正确的,我没有发现他没有出口它。将更新。谢谢 – Sean