Error Meteor.user (): Uncaught TypeError: cannot read property 'name' from null

Im works with the Meteor framework and gets into this error when I try to return the name of the current user to the template helper.

Template.user.userName = function (){ return Meteor.user().name; } <template name ="user"> {{userName}} </template> 

I keep getting this error: (Error: Uncaught TypeError: Unable to read property name "null")

However, everything works fine with the javascript console.

Any help would be greatly appreciated.

0
source share
1 answer

Meteor.user() returns null if the user is not registered. Therefore, to be safe, you have to do something like Meteor.user() ? Meteor.user().name : '' Meteor.user() ? Meteor.user().name : '' .

+5
source

Source: https://habr.com/ru/post/1201254/


All Articles