To authenticate,i have sent post request to server from backbone.js like this
model.save({"email":"sil@gmail.com","password":"silvester"}, {
successs:function(model,res){
},
error:function(){
}
});
i have received in server side like this
app.post('/login', passport.authenticate('local', {
successRedirect: '/mainpage',
failureRedirect: '/login'
}));
in above coding if authentication success i redirect to mainpage and then i have tried to show another one html page like this
app.get('/mainpage',function(req,res) {
console.log("mainpage");
res.sendfile('/mainpage.html');
});
after redirect that mainpage i got that console result but i could not redirect to another webpage. how to work it out and then is there anyway to send response only for that post request(above mentioned post request).if i send response to that post request i can easily receive that response within success function and then i can proceed my work but in passport there is only redirect option so it is going to another get request ,from this how can i sent response to frontend ? and where can i receive ?.so how to send response without redirect and how to solve this one.anyone solve this. thank you
model.save will make an ajax request to your server.
I think when you do res.sendfile('/mainpage.html');, it returns the html page in ajax response. Can you check in Developer Console in the browser?
you should check that if the request is ajax then return a 401 http status code and do the redirection on the client side using window.location="/mainpage.html"
it may help you to respond to same post request
app.post('/login', passport.authenticate('local', { failureRedirect: '/login' }), function(req, res) { res.redirect('/mainpage'); });