Search code examples
meteorspacebars

Check user email status before page loads


I'm using an unless spacebar function to check if a user has verified their email address. In production, I assume due to a delay, the screen displays this notice and then changes after a second if the email has been verified. Is there a way to slow down the page load so the users email status is checked before the page loads?

<template name="mainLayout">

        {{#unless currentUser.emails.[0].verified}}
            <p class="alert alert-warning text-center">We have sent you an email to verify your email address. All users must confirm their email address to access the BHR platform.</p>

        {{else}}

        <div id="content" class="content">
            <div class="container">
                {{>Template.dynamic template=main}}     
            </div>      
        </div>

        {{/unless}}

    </div>

</template>

Solution

  • The delay come because the first time the template is rendered the Meteor.user() object has not yet been fully loaded. Then it loads and reactively the sections get swapped.

    You need to show a loading screen/spinner while the user object is loading. How you do this will depend on what router you are using.