Iron router onBeforeActions 正在重定向到起始页
Iron router onBeforeActions is redirecting to startpage
我使用 onBeforeActions 检查用户是否登录,他们的个人资料是否不完整或被禁用。这似乎工作正常。
但现在的问题是,每当我直接转到应用程序中的某个页面时,我也会被重定向到 startPage。我调试并发现 'user' 未定义,尽管我已登录。我使用 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.loggingIn() return 是什么意思?这是我在 Coffeescript 中使用 Iron Router 进行的登录检查。
requireLogin = ->
if not Meteor.user()
if Meteor.loggingIn()
this.render this.loadingTemplate
else
this.render 'accessDenied'
else
this.next()
尝试像这样简单的事情,然后再添加一些你想做的事情。但我相当确定 Meteor.loggingIn() 是您在这里寻找的东西。
这是它的文档:http://docs.meteor.com/#/full/meteor_loggingin
编辑:它可能在本地工作,因为没有任何延迟,所以如果您登录,它可以立即 运行 一切。如果说得通。
我使用 onBeforeActions 检查用户是否登录,他们的个人资料是否不完整或被禁用。这似乎工作正常。
但现在的问题是,每当我直接转到应用程序中的某个页面时,我也会被重定向到 startPage。我调试并发现 'user' 未定义,尽管我已登录。我使用 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.loggingIn() return 是什么意思?这是我在 Coffeescript 中使用 Iron Router 进行的登录检查。
requireLogin = ->
if not Meteor.user()
if Meteor.loggingIn()
this.render this.loadingTemplate
else
this.render 'accessDenied'
else
this.next()
尝试像这样简单的事情,然后再添加一些你想做的事情。但我相当确定 Meteor.loggingIn() 是您在这里寻找的东西。
这是它的文档:http://docs.meteor.com/#/full/meteor_loggingin
编辑:它可能在本地工作,因为没有任何延迟,所以如果您登录,它可以立即 运行 一切。如果说得通。