Meteor.loginWithPassword redirects


#1

Today I updated iron:router from 0.9.4 to the newest version. I can’t imagine this is caused by iron router but since then, when I call Meteor.loginWithPassword, even if it’s just Meteor.loginWithPassword('', '') from the console, I get redirected from /login to /. I have no idea why this could happen. I don’t get any logs in the console, just server-side logs telling me the login has failed.

Any idea?


#2

Yeah, it is something in your code. When I setup a virgin project with iron router and accounts password this does not happen


#3

I am actually having a similar issue. Meteor.loginWithPassword() some how triggers a route to ‘/’. I can see this happening because I have a Iron Router global Router.onBeforeAction being triggered regardless of whether the login succeeds of fails. @fvg did you ever figure this out?


#4

It happens with me too, probably because of the reactivity of the hooks.


#5

@fvg @borges Hey guys. I actually ended up figuring it out for my app. Hopefully my issue will help solve yours. So in my Iron Router code, I have a typical global Router.onBeforeAction hook that checked on all route changes if a user was logged in. My issue was that I was also checking while a user was loggingIn as well. The below change fixed the redirect that was happening.

This caused the unwanted reload

Router.onBeforeAction(function() {
if (Meteor.userId()) {
this.next();
} else if(Meteor.loggingIn()) {
//Insert logic
}else{
Router.go(’/’);
}
});

This fixed it so there was no reload

Router.onBeforeAction(function() {
if (Meteor.userId()) {
this.next();
}else{
this.redirect(’/’);
}
});


#6

Impossible to be simpler than that. Thanks!


#7

@borges Glad I could help! It drove me crazy last night :stuck_out_tongue_closed_eyes: