Iron 路由器注销期间的 Meteor 用户配置文件未定义错误
Meteor User profile undefined error during iron router's logout
我在助手中使用 Meteor.user().profile。当我注销时,我得到未定义的错误配置文件。我的代码如下:
Template.listedWork.helpers({
workList: function() {
if (Meteor.user().profile.yetki == 1) {
return Work.find({})
} else {
return Work.find({
username: Meteor.user().username
});
}
}
});
我正在 listedWork 页面中注销,例如:localhost/listedWork。那是铁路由器渲染代码
Router.route('/listedWork', {
action: function() {
this.render('listedWork');
},
onBeforeAction: function() {
if (!Meteor.userId()) {
this.layout("loginLayout");
this.render('login');
} else {
this.next();
}
}
});
当我在此处注销时,Meteor.user().profile 由 workList 调用,这就是我收到此错误的原因。
用于注销的登录模板在 onBeforeAction 中呈现。为什么 listedWork 模板助手在这里调用它。
感谢大家的帮助。
注销后 Meteor.user().profile 未定义的原因是因为您不再有 Meteor.user()。如果 Meteor.user() returns null.
,您需要在助手中检查并执行适当的操作
Template.listedWork.helpers({
workList() {
if( !Meteor.user() ) {
// Handle the case. Redirect to /login or something.
}
else {
// Your current helper code here.
}
}
});
我在助手中使用 Meteor.user().profile。当我注销时,我得到未定义的错误配置文件。我的代码如下:
Template.listedWork.helpers({
workList: function() {
if (Meteor.user().profile.yetki == 1) {
return Work.find({})
} else {
return Work.find({
username: Meteor.user().username
});
}
}
});
我正在 listedWork 页面中注销,例如:localhost/listedWork。那是铁路由器渲染代码
Router.route('/listedWork', {
action: function() {
this.render('listedWork');
},
onBeforeAction: function() {
if (!Meteor.userId()) {
this.layout("loginLayout");
this.render('login');
} else {
this.next();
}
}
});
当我在此处注销时,Meteor.user().profile 由 workList 调用,这就是我收到此错误的原因。
用于注销的登录模板在 onBeforeAction 中呈现。为什么 listedWork 模板助手在这里调用它。
感谢大家的帮助。
注销后 Meteor.user().profile 未定义的原因是因为您不再有 Meteor.user()。如果 Meteor.user() returns null.
,您需要在助手中检查并执行适当的操作Template.listedWork.helpers({
workList() {
if( !Meteor.user() ) {
// Handle the case. Redirect to /login or something.
}
else {
// Your current helper code here.
}
}
});