mysql - How to send a json response to broswe using passport -


Hello, I am trying to login local through passport. Everything works well, but I want to be able to display the user name once the user here node My code has been certified using JS and MISCIL:

  passport.use (new localtrategy ({usernameField: 'email', passwordField: 'password', passReqToCallback: true // We have to return the full request to callback}, function (request, email, password, done) {var status = []; console.log ('-----'); connection.query ('SELECT user User by name (where rows length) {status.push ({username: lines [0]. Username (email) = "'+ + + email +", function (error, address) } {If (err) return done (err);}); (zero, JSON.stringify (status)); // output as JSON //console.log (JSON.stringify (status)); // ('' Status '': '+ JSON.stringify (status));}});}); App.post (' / login ', passport. Authentication (' local ', {successRedirect:' / LoginSuccess', loginRedirect: '/ loginFailure', failureFlash: false});; App.get ('/ loginFailure', function (Rick, Race, Next) {res.send ('Failed to authenticate');}); App.get ('/ loginSuccess', function (Rick, Race, Next) {res.send ('Successfully certified');});  

Assume that your certification is working properly, to be used by passport The user data stored is req.user variable on each request. Passing the req.user variable in your thoughts will give you user information.

Also see the works used by serial lauge user () and deserillize user () passport. You do not show them in your code, but for the purpose of the session they are required by the passport, in fact, certifies your local user, the serializer () creates session session data, and the deserializeUser () function reads session data And req.user makes variables.


Comments