简体   繁体   中英

Check login in FlowRouter in Meteor

I am using FlowRouter in Meteor.

On some pages, I want to check if the user is logged in, so I have made a triggerEnter function

const isAuthenticatedRedirect = ( context, redirect, stop ) => {
  if ( ! Meteor.loggingIn() && ! Meteor.userId() ) {
    FlowRouter.go( 'login' );
  }
};

const isAuthenticatedRoutes = FlowRouter.group( {
  name: 'isAuthenticated',
  triggersEnter: [ isAuthenticatedRedirect ]
} );

The problem is that it redirects the user to /login rather than just showing the login template.

I could make an if statement on all the pages, and then show the login instead of the real page if the user is not logged in, but I guess it would be way smarter to do it directly in the router.

FlowRouter does not allow you to render the template, thus redirect is the only option. You need to install the other package to make it render directly instead of using FlowRouter.go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM