【问题标题】:Iron router onBeforeActions is redirecting to startpageIron 路由器 onBeforeActions 正在重定向到起始页
【发布时间】:2015-07-20 02:51:27
【问题描述】:

我使用 onBeforeActions 来检查用户是否已登录,他们的个人资料是否不完整或已禁用。这似乎工作正常。

但现在的问题是,每当我直接进入应用程序内的页面时,我也会被重定向到 startPage。尽管我已登录,但我调试并发现“用户”未定义。我使用 accounts-fb & -tw 和 account-ui 包。

如何确保用户已登录?我不明白功能的正确时间安排..

编辑: 在本地,我似乎并不总是有这个问题。用户经常被定义。但是在我的生产服务器上(我只是用调试器语句上传它,是的,我没有测试服务器:/)它似乎总是未定义并将我转发到 startPage..

router.js:

if (Meteor.isClient) {
// only for client, else the serverside router will try to run this onBeforeAction
var onBeforeActions;

onBeforeActions = {
    loginRequired: function() {
        var user = Meteor.user();
        if (!user) {
            Router.go('startPage');
        } else {
            if (user && user.profile && user.profile.incomplete) {
                Router.go('completeSignup');
            }

            if (user && user.profile && user.profile.disable) {
                Router.go('profileEdit');
            }
        }

        this.next();
    }
};

Router.onBeforeAction(onBeforeActions.loginRequired);

Router.configure({
    notFoundTemplate: 'notFound', 
    layoutTemplate: 'layoutMain',
    loadingTemplate: 'loading',
    trackPageView: true
});

Router.map ({});

}

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    用户是否正在登录? Meteor.loggingIn() 返回什么?这是我在 Coffeescript 中使用 Iron Router 进行的登录检查。

    requireLogin = ->
      if not Meteor.user()
        if Meteor.loggingIn()
          this.render this.loadingTemplate
        else
          this.render 'accessDenied'
      else
        this.next()
    

    尝试像这样简单的事情,然后添加一些你想做的事情。但我很确定 Meteor.loggingIn() 就是您要在这里寻找的。​​p>

    这是关于它的文档:http://docs.meteor.com/#/full/meteor_loggingin

    编辑:它可能在本地工作,因为没有任何延迟,所以如果你登录它可以立即运行一切。如果这有意义的话。

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 2015-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多