node.js - Passport (local) is hanging on Authentication -


I have a passport local strategy that is established in the form of the following, although none of the cases of failure works fine , Where I authenticate the server, "d1" logs in and then hangs, with the remaining request in a "pending" condition:

  passport.use (new localetracy ({ UsernameField: 'email', password-field: 'password'}, function (email, password, done) {user.getUser (email, password). Then (funk Shun (user) {if (user and users.length == 1) {console return (blank, user [0]);} other {console.log ('d2') returned (empty, false, { Message: 'Incorrect credentials.'})}}} Function (e) {console.log ('d3') returned (empty, false, {message: 'wrong credential.'});});})); Passport.serializeUser (function (user, done) {console.log ('s1') done (zero, user);}); Passport.deserializeUser (function (user, done) {console.log ('s2') done (tap, user);}); Server.post (authPostRoute, passport.authenticate ('local', {successRedirect: "/ idea", failure redirect: "/",})));  

Ideally I do not want to be redirected to success / failure, and some JSON should be withdrawn in the browser. But I do not seem to be working on this simple scenario.

Updates - Passport-Local / Strategy JS

is verified by this function strategy.js

  function (error, user, info) {if (err) {return self.error} (Err); } If (! User) {return self.fail (info); } //console.log (self.success.toString ()) self.success (user, info); }  

All that is good is Self.success seems to be a legitimate work, yet it is not being implemented, as I can tell.

Update Second: Passport / Certified. Js

  strategy.success = function (user, info) {}  

me

  req Do not enter functions in .logIn (user, option, function (mistake) { 

). I miss a definition of

Update III: Login

Tracing through passport / http / prequest.js, this line Apparently this is the cause of the issue

  If (! This._passport) new error ('passport.in initialize (middleware is not in use');  

However I thought I have enabled it with:

  server.use (passport.initialize ());  Update   The Rect seems to work  

But I'm still unable to control the customer's response. I do not want to redirect. Is this a different question?

I experienced a similar problem and passport.initialize The problem has been solved, thanks a lot.

But I'm still unable to control the customer's response. I do not want to redirect. Is this a different question?

If anyone with this question; You can use callback like this for custom logic.

router post ('/ login', function (rik, ridge, next) {passport.authenticate ('local-signin', function Err, user, info) {if (err) {Return next (err);} if (! User) {return res.render ('account / login', {pageTitle: 'sign in', form: req.body});} Req.logIn (user, function ( Mistake) {if (mistake) {back next (mistake);} return res.redirect ('/ myaccount');})}} (rik, ridge, next);});

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -