Search code examples
meteorflow-router

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?


Solution

  • 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
    }