[英]METEOR Iron router redirect when it shouldn't
我有这个onBeforeAction挂钩,在该挂钩中,我检查用户是否未以特定角色(在这种情况下为雇主角色)登录或未登录,然后将其重定向到特定页面(称为验证)。 我可以很好地导航到该页面,但是当我已经在页面上并单击REFRESH时,似乎他通过了IF条件并继续使用Router.go("verification");
编码:
Router.route("/employer/profile", {
name:"employerProfile",
template:"employerProfile",
layoutTemplate:'employerLayout',
onBeforeAction:function(){
var user = Meteor.userId();
if(!user || !Roles.userIsInRole(user, ['employer'])) { // checking if the user satisfies this condition e.g. if its a "GUEST USER" than he can't access this route
Router.go("verification");
}
else {
this.next();
}
return true;
},
});
这是一个快速的视频演示,演示发生了什么:
http://screencast.com/t/BEgwpXwqvwt
有人有主意吗?
看起来在页面刷新上,Meteor订阅了Roles集合,但尚未下载任何数据,因此userIsInRole返回false。
我认为您要么需要等到角色订阅准备就绪(这不是最佳选择),要么稍后再等到订阅准备就绪时重定向到验证页面。 我建议使用服务器方法进行此检查。 将验证代码移动到服务器方法中,以供使用:Meteor.call('verifyUser',函数(错误,结果){if(result === false)Router.go(“ verification”);});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.