Different routes for first time login and subsequent logins


#1

I’m a meteor newbie and was trying to build an app feature in which when user signs up for the first time, he is taken to a page where he has to fill some questions. For subsequent logins, the user should be redirected to a different page. How can we implement this on meteor?

PS: Open source projects with a similar feature/ code tutorials will be appreciated alot and will be repayed by a giant hug :D! Thanks!


#2

The easiest way to solve this is to have a collection for the information you want to get with the sign up questions. Then have a field in that collection that is initially false and is only set to true when they answer the questions. Then you have a before route action that checks whether it is set to true before going to the home page and if its false it goes to the first time login page. This makes it easy since when they submit their answers (you set the value to true) and then redirect them to the home page and since its now true they will go directly to the home page instead of the sign up page.

If you haven’t decided on a router Iron Router is go to router that most people use, though there is Flow Router which is more light weight but also has less features.

Have you had a chance to go through the Meteor tutorial on the meteor site? Discover Meteor is also a great resource and it worth the money. Though if you are looking for just free resources there are a bunch too pick from http://meteorhelp.com/


#3

@entropy Thanks mate! I’m currently working on this https://github.com/michael-pr/HourTracker project to understand meteor. It already has iron-router built in.
So I build a collection of fields and a “isfirstlogin” set to 0/1. On first time login,the user is redirected and a hidden fields puts a 1 value to the db.
How do i make the iron router to compare this to 0 or 1 and redirect?


#4

Something like this is the method I would use:

Router.onBeforeAction(function () {
  if (UserDetails.findOne({_id: Meteor.userId()}).completedSignUp == 0) {
    // if the user has not completed the signup
    Router.go('signUpDetails');
  } else {
    this.next();
  }
}, {
  except: ['signUpDetails']
});