Search code examples
meteorreactjstemplate-enginemeteor-blaze

Send Meteor Template to client on condition


I've been playing with Meteor recently, and one thing I can't wrap my head around is how to publish templates based on a certain condition, before they are sent to the client-side. Example:

<head>
    <title>Some partially authenticating app</title>
</head>
<body>
    {{> unauthorisedContent}}
    {{> authorisedContent}}
</body>

What I want to do is send the {{> authorisedContent}} template if and only if the client is logged in, and not send it then conditionally and then exclude it based on if (!!Meteor.user()) on the client side. How can this be achieved? Is this also possible using React JS for Meteor instead of Blaze?


Solution

  • This is not currently possible within the same Meteor application. Your two options for addressing this are:

    1. Have a separate application for authorized content versus unauthorized content.
    2. Ensure that you're not publishing data to unauthorized users who happen to figure out how to get the authorized content template to show up.

    Most people go with option #2.