简体   繁体   English

流星路由器在开发模式下工作,但不在生产模式下工作

[英]Meteor router working in dev mode but not in production mode

I'm trying to protect an admin page, so I created a role for it. 我试图保护管理员页面,所以为它创建了一个角色。 I'm using iron:router for the routes, and in production mode I have an issue: everytime I type the url/admin in my browser, I end up in /user (it's the login page). 我正在使用iron:router进行路由,在生产模式下,我遇到了一个问题:每次在浏览器中键入url / admin时,我都以/ user结尾(这是登录页面)。 I don't have this issue in dev mode ! 我在开发人员模式下没有这个问题! I really don't get why 我真的不明白为什么

Here is the code: 这是代码:

var middleware;

middleware = {
  isAdmin: function() {
    var user;
    user = Meteor.user();

    if (!Roles.userIsInRole(user, ['admin'])) {
      this.redirect('user');
      return;
    }

    return this.next();
  }
};

And for the router: (in 对于路由器:(在

Router.map(function() {
  this.route('user', {
    path: '/user'
  });
  return this.route('admin', {
    path: '/admin',
    before: [middleware.isAdmin]
  });
});

I had this issue previously. 我以前有这个问题。 The problem is the delay in Meteor identifying you are a logged in user. 问题是流星识别您是登录用户的延迟。

When navigating within the app, Meteor.user() remains set, so you can reach your route. 在应用程序中导航时, Meteor.user()保持设置,因此您可以到达自己的路线。 When typing in the URL, you perform a full page refresh so the route hook is called before Meteor can finish logging you in. 输入URL时,将执行整页刷新,以便在Meteor完成登录之前调用路由挂钩。

Therefore, user = Meteor.user(); 因此, user = Meteor.user(); will set user to null and you are redirected to the user page. user设置为null ,您将被重定向到用户页面。

You can use Meteor.loggingIn() to check whether the login process is still ongoing. 您可以使用Meteor.loggingIn()来检查登录过程是否仍在进行中。 Iron Router's waitOn hook can be used for this (or just setting a timed delay will probably do the trick in most cases). 可以将Iron Router的waitOn挂钩用于此操作(或者在大多数情况下仅设置定时延迟就可以解决问题)。

So in fact I just used fast-render, which automatically solves my problem. 所以实际上我只是使用了快速渲染,它可以自动解决我的问题。 Hope it'll help somebody ! 希望对别人有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM