Search code examples
javascripthtmlmeteor

export table data into excel in meteor


In my application starting URL localhost:3000 takes me login page and after I login, it takes to /afterlogin for now every thing working fine, once I remove /afterlogin and enter it will take to login page again how to block that url after login and stay in home page in meteor?


Solution

  • Rather than use / as the URL for user login, the more "Meteor.js" thing to do is use conditional logic in the main template for your site's landing page. The Meteor documentation for Accounts explains that applications should:

    Use {{#if currentUser}} to check whether the user is logged in.

    Check out the login example application to see how {{#if currentUser}} is applied in practice. I've copied the template below for convenience:

    <template name="main">
      {{#if loggingIn}}
        <div class="loading">Loading...</div>
      {{else}}
        {{#if currentUser}}
          <div class="msgDiv">
            Signed in as: {{currentUser.services.google.email}}
          </div>
          <a href="#" id="logout">Sign out</a>
        {{else}}
          <a href="#" id="login">Sign In With Google</a>
        {{/if}}
      {{/if}}
      <div class="msgDiv">
        Client can see {{numGizmos}} gizmos.
      </div>
    </template>
    

    In the "main" template, you can see that the application uses Spacebars to check for the following conditions:

    • if loggingIn is true (the user is logging in), display a loading screen
    • if loggingIn is false AND currentUser is true (the user has already logged in), display a screen with the signed in user's information
    • if loggingIn is false AND currentUser is false (the user hasn't signed in yet), display a prompt to sign in

    Note: in this example application, they demonstrate login with the accounts-google authentication package, but you can use the same pattern for the basic accounts-password based login. Other authentication packages include accounts-facebook, accounts-github, accounts-twitter, and community packages.

    If you are using iron:router in your application, then you can also secure the application URLs with logic like the following (taken from the docs):

    Router.onBeforeAction(function() {
      if (! Meteor.userId()) {
        this.render('login');
      } else {
        this.next();
      }
    });