THpubs
THpubs

Reputation: 8172

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

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?

Upvotes: 0

Views: 521

Answers (1)

LazyCat01
LazyCat01

Reputation: 1039

The method you need is Meteor.loggingIn()

Before redirecting user you need to check if user is logging in like:

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

Upvotes: 2

Related Questions