got quite a complicated problem.
In my application, there is a 5 step user registration/setup process.
After these steps, the user has access to the dashboard.
What I want to do is make sure that
I'd really appreciate any help on how to do this. So far what I've done is create a field in the database attached to the user document which records what step they have completed last, and if they have completed all it stored "dashboard".
I'm using Iron Router and I think the answer may lie in onBeforeAction hooks but I'm not 100% sure.
Any help appreciated!
I actually managed to work this out so thought I'd post for anyone who has a similar issue.
I extended the route controller for the routes I want to protect. The extended controller calls a meteor method that returns the value in the database that is stored when a user completes a registration step. I stored this value as a string which is the route the user should be redirected to.
So now, when a user signs up and completes step 2 then logs out a few things happen.
Meteor.user().loginRedirectTo = '/subscribe'
)Here's the code for it
Extended Controller:
StageController = RouteController.extend({
onBeforeAction: function() {
Meteor.call('getUserRedirect', function(error, route) {
if(error) {
console.log(error);
} else {
Router.go(route);
}
});
this.next();
}
});
Meteor method to return route user needs to go to:
Meteor.methods({
'getUserRedirect': function () {
if(!Meteor.userId()) {
throw new Meteor.Error(401, "You aren't even logged in, stop calling methods!");
}
var user = Meteor.user();
var redirectRoute = Meteor.user().loginRedirectTo;
return redirectRoute;
}
});
And finally assign that controller to each of the routes with this code:
Router.route('/dashboard', {
template: "dashboard",
name: "dashboard",
controller: "StageController"
});