if (Meteor.isClient) {
console.log(Meteor.user().profile.name);
}
Why does not this code?
Uncaught TypeError: Cannot read property ‘profile’ of undefined
if (Meteor.isClient) {
console.log(Meteor.user().profile.name);
}
Why does not this code?
Uncaught TypeError: Cannot read property ‘profile’ of undefined
fix
if (Meteor.isClient) {
Meteor.startup(function () {
console.log(Meteor.user().profile.name);
});
}
Also, there is a chance that name
will be undefined as well which will crash your templates. Just to ease development I usually do checks for nested objects so they don’t return undefined.