2
\$\begingroup\$

The site should be accessible only to signed-in users. I'm making sure I publish and enable data manipulation to only those, but I wanna make sure even the app structure won't be visible.

What I did was creating an autorun that checks for changes in signed-in user and reloads the router. The router takes care of redirecting if needed.

let first_time = false;
Tracker.autorun(() => {
    Meteor.userId();
    if(first_time)
        FlowRouter.reload();
    else
        first_time = true;
});

FlowRouter.route(States.home,{
    triggersEnter: [(context, redirect) => {
        if(!Meteor.userId())
            redirect(States.login);
    }],
    action(params,queryParams){
        BlazeLayout.render('SimpleLayout', { content: "App"});
    }
});

FlowRouter.route(States.login,{
    action(params,queryParams){
        BlazeLayout.render('SimpleLayout', { content: "Login"});
    }
});

Are there any flaws?

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.