Im working with the Meteor framework and came by this error when I tried to return the name of the current user to a template helper.
Template.user.userName = function (){
return Meteor.user().name;
}
<template name ="user">
{{userName}}
</template>
I keep getting this error: (Error: Uncaught TypeError: Cannot read property ‘name’ of null)
However everything works fine from the javascript console.
Any help would be much appreciated.
Meteor.user()returns null if there is no user logged in. So to be safe you should do something likeMeteor.user() ? Meteor.user().name : ''.