javascript - Passport js login from cross-domain? -
How can a user log in from another domain? The entry form and Ajax posts of the main site have been sent to a root on my NodesJS server. Submit form on node server (app) with
// website $ ('# submit-project-form') .submit (function (e) {e.preventDefault (); var formData = $ (This) .serialize (); $ .ajax ({url: "http: // localhost: 3100 / login", data: formdata, type: "POST", crossDomain: true, dataType: "json", success : Function (feedback) {console.log (response.responseText);}, error: function (response) {var success = $ ($ .parsseHTML (response .responseText)). Filter ("body"); console.log ( Response.responseText);}});}); // Passport Post Method Methods Listen to the route to website postpay ('/ login', 'local login', {successRedirect: '/', // re-run user.index, which should be in the form of a user Should and provide profile failure again: '/ login', // redirect back to the signup page if there is an error failure Flash: true}));
This route turns on, and I'm getting the required email and password to login for the passport strategy.
passport.use ('local login', new localtrategy (userform field: 'e-mail', password field: 'passwords', pass recticbank: true // to return the full request to callback ), Function (rick, email, password, done) {// callback in our form console.log (req.body.email); // Return email in the cross-domain area console.log (email) E-mail return email is entered in the cross-domain field / any Find the user whose emails are email as the same email / We are looking to check that the user is trying to login, already appUser.findOne ({'local.email': email}, the function ( Mistake, user) {// If there is any error, anything returned before error (mistake); // If no user is found, return message if (! User) returns d one (empty) , Wrong, req.flash ('login message', 'no user Not found. ')); // req.flash is the way to set flash data using connect-flash // if the user is found but the password is incorrect (if! User.valid password (password) returned (blank, wrong, req.flash ('login message', 'oh! Wrong password.')); // Create a log-in message and save it to FlashData // Everything is OK, successful user returned (blank, user); }); }));
CORS is enabled on NodesJS server, it works because I am able to deposit payments, and I get a response from the server
I think the problem Passport has success redirection
and there is a problem in it, can I need a custom success function? Any ideas?
Looks like xhrFields
added in Ajax I will continue to do so, but I was able to login with a cross-domain post, very good.
xhrFields: {with credentials: true},
Comments
Post a Comment