Currently have a user in the system with the role ‘Super-User’. In the database it’s showing ‘Super-User’ however output on my code is showing the roles array as being null.
My Client Code calling the user (returning all user data but listing roles as null)
const handle = Meteor.subscribe('users.current',Meteor.userId());
Tracker.autorun(() => {
const isReady = handle.ready();
if(isReady) {
}
console.log(Meteor.user());
console.log(Meteor.users.findOne(Meteor.userId()));
});
My Subscribe:
Meteor.publish('users.current', function (passedId) {
const selector = {_id: passedId};
console.log(this.userId);
const options = {
fields: {_id: 1, "roles": 1}
};
const response = Meteor.users.find(selector,options);
return response;
});
I’m using Astronomy for data modeling.
const User = Astro.Class({
name: 'User',
collection: Meteor.users,
fields: {
'emails': {
type: 'array',
nested: 'Email',
default: function() {
return [];
}
},
createdAt: 'date',
profile: {
type: 'object',
nested: 'UserProfile',
default: function() {
return {};
}
},
roles: {
type: 'array'
},
company: {
type: 'string'
}
},
methods : {
firstEmail : function () {
return _.get(this, 'emails[0].address', null);
}
}
});
EDIT: possible issue might be with the subscription itself. When I console.log out isReady within autorun it never shows true.