vendredi 17 avril 2015

What is the best way to redirect using Meteor/Iron Router a user that is logged in to Facebook?

I am new to Meteor and am building an app for mobile (with Cordova). I need my user to login via Facebook. Once the user is logged in though, the app must redirect to the next page (which is mapped to '/hotelSelect').


Below, I have used Router.go, which works but when the app is opened again you can see the login page for a split second! Also, my server throws the following exception:



Exception in onLogin callback: TypeError: Object function router(req, res, next) {
//XXX this assumes no other routers on the parent stack which we should probably fix
router.dispatch(req.url, {
request: req,
response: res
}, next);
} has no method 'go'
at Router.map.route.path (app\lib\router.js:9:9)


What is the best (most correct way) to do this? I've been looking all over the net for an answer but haven't been able to find a good straight-up answer. Thanks a tonne :-)



Accounts.onLogin(function(){
Router.go("/hotelSelect"); //check if logged in and reroute.
})

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


Router.map(function(){
this.route('login',{path:'/'});
this.route('currentlyAt',{path:'/currentlyAt'});
this.route('hotelSelect',{path:'/hotelSelect'});
this.route('reqHistory',{path:'/reqHistory'});
this.route('preCheckin',{path:'/preCheckin'});
this.route('hotelServices',{path:'/hotelServices'});
this.route('roomNumber',{path:'/roomNumber'});
})

Aucun commentaire:

Enregistrer un commentaire