How to wait for Meteor.user() and redirect if undefined from within the container?

时间:2016-06-10 16:13:18

标签: meteor flow-router

I want restrict non logged in users from viewing some pages in my app by redirecting them to the login page. I use react, flow router and the react komposer. The problem is, Meteor.user() first gives undefined and even-though the user is logged in, he gets re-directed into the login page. How can I fix this?

1 个答案:

答案 0 :(得分:2)

您需要的方法是Meteor.loggingIn()

在重定向用户之前,您需要检查用户是否正在登录:

if(!Meteor.loggingIn() && !Meteor.userId()){
   //do redirect to login page
}