I’m trying to add a field to the user collection admin as a boolean that will track if a user is an admin or not.
I made the schema as such.
UserSchema = new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id
},
emails: {
type: Array,
},
username: {
type: String,
optional:true
},
"emails.$": {
type: Object,
blackbox: true
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean,
optional: true
},
profile: {
type: ParentProfile,
optional:true
},
services: {
type: Object,
optional: true,
blackbox: true
},
admin:{
type: Boolean
}
});
I want this on default to set to false so I have it set on onCreated user as such:
Accounts.onCreateUser(function (options, user) {
if (user.services.google) {
user.username = user.services.google.name;
user.emails = [{address: user.services.google.email}];
}
else if(user.services.facebook) {
user.username = user.services.facebook.name;
user.emails = [{address: user.services.facebook.email}];
}
user.admin = false;
return user;
});
});
However on creation it does not add the admin field, but it does do the username portion correctly.
Also I have put in a button that should add the admin field and set it to true… but it only appears to set it temporarily and then it seems to loose the admin field all together again
Template.ShowUser.events({
'click .makeAdmin' : () => {
Meteor.users.update(this.id, {$set : { admin: true }});
console.log(Meteor.user());
}
});
So when it prints the user here it shows the admin is set to true… but then when i go back to the profile the admin field as disappeared again.
What am i missing here?
Also I tried to jsut put it as a field in their profile… but when using the autoform it didnt seem to want to set the auto or default value and thus would not add the record unless i left the field optional. This is the profile schema I am using:
ParentProfile = new SimpleSchema({
firstName: {
type: String,
label: "First Name"
},
lastName: {
type: String,
label: "Last Name"
},
birthday:{
type: Date,
autoform: {
type: "bootstrap-datepicker",
datePickerOptions: {
autoclose: true
}
}
},
zipcode:{
type: String,
label: "Zip Code",
autoform:{
mask: '00000',
type: 'masked-input',
placeholder: '00000'
}
},
admin:{
type: String,
optional: true,
autoform:{
type: "hidden"
},
defaultValue: "no",
autoValue: () => {
return "no";
}
}
},{
clean:{
filter: true,
autoConvert: true,
removeEmptyStrings: true,
getAutoValues: true,
}
});
Autoform seems to be missing alot of functionality, is there a better package to be using? O r should I just be doing all of this myself? I was trying to use simple-schema and autoform to make it easier but it just seems to not want to work properly for anything advanced, or am I missing something?
I tried to set the form to clean before submitting but that functionality still did not solve the problem, it seems this may be an issue with autoform and nested objects?
Can someone please give some advice on how to solve this issue?