ajax - CORS Logging into an expressjs/passportjs app 401 Unauthorized -
i converting web app cordova app thing stopping me fact app expressjs based, since cordova requires index.html need use cors render app , provide login session.
i can use ajax/cors regular pages when comes authorization stuck.
i use passportjs authenticate on post route app.post('/login', passport.authenticate('local-login'));
on client side cordova app make ajax call make request me.
$('body').on('submit', '#login', function(e){ e.preventdefault(); var formdata = $(this).serialize(); console.log(formdata); $.ajax({ url: "http://mysite.io:3300/login", data: json.stringify(formdata), type: "post", crossdomain: true, datatype: "json", async: true, success: function(response){ alert('succeeded!'); console.log(response); alert(response); }, failure: function(message){ alert("failed"); console.log(message); alert(message); } }); });
when make post request 401 unauthorized
have been doing research on that, still not sure why it's not authorizing?
from passport docs:
by default, if authentication fails, passport respond 401 unauthorized status, , additional route handlers not invoked.
the username/password combination you're posting not valid.
Comments
Post a Comment