I’ve been trying to create a userProfile
by attaching additional information to Meteor.users
using the following packages:
-
aldeed:simple-schema
-
aldeed:Collection2
-
aldeed:AutoForm
The update form generates and populates with the registered email address however I can’t get the submit button to update anything to the database. From the information I’ve read I believe it might be something to do with publish or I need to add a method.
I’m new to programming and meteor could you please be clear and show the code.
My code is below.
Path: collections/UserProfile.js
Schema = {};
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
optional: true
},
lastName: {
type: String,
optional: true
},
birthday: {
type: Date,
optional: true
},
gender: {
type: String,
allowedValues: ['Male', 'Female'],
optional: true
}
});
Schema.User = new SimpleSchema({
emails: {
type: Array,
// For accounts-password, either emails or username is required, but not both. It is OK to make this
// optional here because the accounts-password package does its own validation.
// Third-party login packages may not require either. Adjust this schema as necessary for your usage.
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date,
autoValue: function() {
return new Date()
},
autoform: {
type: "hidden"
}
},
profile: {
type: Schema.UserProfile,
optional: true
},
// Make sure this services field is in your schema if you're using any of the accounts packages
services: {
type: Object,
optional: true,
blackbox: true,
autoform: {
type: "hidden"
}
}
});
Meteor.users.allow({
update: function(userId, doc) {
return !!userId;
}
});
Meteor.users.attachSchema(Schema.User);
Path: client/UserProfile.js
Template.UserProfile.helpers({
user: function(){
return Meteor.user();
},
userSchema: function () {
return Schema.User;
}
});
Path: client/UserProfile.html
<template name="UserProfile">
{{> quickForm collection="Meteor.users" id="user-profile-form" type="update" doc=user}}
</template>
Path: server/publish.js
Meteor.publish('allUsers', function () {
return Meteor.users.find();
});
Why is this happening and how can I fix it?