铁路由器onBeforeActions重定向到起始页 [英] Iron router onBeforeActions is redirecting to startpage
问题描述
我使用onBeforeActions来检查用户是否已登录,如果他们的个人资料不完整或被禁用.这似乎正常工作.
I use onBeforeActions to check if users are logged in, if their profile is incomplete or disabled. This seems to work correctly.
但是现在的问题是,每当我直接转到应用程序中的页面时,我也会被重定向到startPage.我已调试并发现'user'未定义,尽管我已登录.我使用accounts-fb& -tw和account-ui软件包.
But now the problem is whenever I directly go to a page within the app, I get redirected to startPage as well. I debugged and discovered 'user' is undefined, although I'm logged in. I use accounts-fb & -tw and account-ui packages.
如何确定用户已登录?我不了解这些功能的正确计时..
How can I make sure the user is logged in? I don't understand the correct timing of the functions..
在本地,我似乎并不总是遇到这个问题.用户通常是定义的.但是在我的生产服务器上(我只是用调试器语句上载了它,是的,我没有testserver:/),它似乎总是未定义并将其转发到startPage.
edit: Locally I don't always seem to have this problem. user is often defined. But on my production server (I just uploaded it with a debugger statement, yes I have no testserver :/) it always seems to be undefined and forwarding me to the startPage..
router.js:
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()返回什么?这是我在Coffeescript中使用Iron Router进行的登录检查.
Is the user in the middle of logging in? What does Meteor.loggingIn() return? Here is my login check using Iron Router in Coffeescript.
requireLogin = ->
if not Meteor.user()
if Meteor.loggingIn()
this.render this.loadingTemplate
else
this.render 'accessDenied'
else
this.next()
尝试类似这样的简单操作,然后添加一些您想做的事.但是我很确定Meteor.loggingIn()是您在这里寻找的东西.
Try something simple like this, and then add the little bits of what you want to do after. But I'm fairly sure Meteor.loggingIn() is what you're looking for here.
这里是文档: http://docs.meteor.com/#/full /meteor_loggingin
它可能在本地工作,因为没有任何延迟,因此,如果您登录,它可以立即运行所有内容.如果这样的话.
It probably works locally because there isn't any latency so if you're logged in it can run everything immediately. If that makes sense.
这篇关于铁路由器onBeforeActions重定向到起始页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!