I am trying to redirect the user after they login. So far, I am experiencing something strange when the user enters the correct username and password.
So here's what I got on my server side to login the user, using the post method:
app.post('/login', function(req,res) {
var username = req.body.username;
var password = req.body.password;
User.logIn(username, password).then(function(result) {
console.log(result.getSessionToken());
res.send({redirect: '/overview'});
}, function(error) {
// console.log(error);
res.send({redirect: '/login_failed'});
});
});
And here's what I got on the client side in the HTML code:
$scope.submit = function() {
console.log($scope.username,$scope.pword);
$http.post('/login', {username: $scope.username, password: $scope.pword}).done(function(result, status, jqXHR) {
// console.log(result.data.redirect);
window.location = result.data.redirect;
});
};
When the user enters the wrong username and password, the page has no problem redirecting to /login_failed on the first attempt. But when the user enters the correct username and password, it just refreshes the page and adds #? to the current url (Example: http://localhost:1337/login_page changes to http://localhost:1234/login#?). Now, if the user enters their username and password again, it will successfully redirect to /overview. I've also noticed that when I manually add #? to the url and the correct username and password is entered, the page will redirect on the first attempt.
I've also tried to use res.redirect('/overview'); but that will only redirect me to http://localhost:1234/[object%20Object] and it displays the following message: Cannot GET /[object%20Object].
I really cant understand where the problem is arising from since the user will successfully get redirected to if they enter the wrong username and password. Any pointers or tips will be appreciated.
via Babak Rz
No comments:
Post a Comment