meteorjs检查登录用户

时间:2014-10-17 01:09:52

标签: meteor

我刚刚再次拿起流星,自从我上次处理我的应用程序后,有些事情发生了变化。我目前有1个问题,如果用户没有登录,我想提交登录表单。之前我使用的是:

Deps.autorun(function(){
if(Meteor.userId()==null){
    $(window).load(function(){
        $('#loginModal').modal('show');
    });
}});

哪个工作正常。现在,我得到一个错误:

Meteor.userId只能在方法调用中调用

那么,我现在如何实现上述目标。 提前致谢 亚当

1 个答案:

答案 0 :(得分:1)

以下是我的操作:在服务器端iron:routeralanning:roles你可以做

this.route('EndUserPage', {
      path: '/EndUserPage',
      onBeforeAction: function (pause) {
          if (!(Meteor.user())) {
              console.log("Not logged in");
              this.setLayout('LoginForm');
              this.render('LoginForm');
          } else if (!(Roles.userIsInRole(Meteor.user(), 'admin'))) {
              this.redirect("/AdminPage")
          } else {
              this.render();
          }
      }   });

如果您没有角色套餐,则无法检查它是否为管理员用户,但重定向到登录页面可以按预期工作。

相关问题