【发布时间】: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