我是Nodejs的新手。我正在嘗試返回數據。選擇查詢後。在這裏,我寫了兩個條件。首先是非常簡單的邏輯,它正在工作,但讓我知道爲什麼第二個條件不起作用。Nodejs,返回條件不起作用
第一個條件:
var arr = {email:"[email protected]", password:"};
return arr;
databaseConnection.query("SELECT * FROM users where email = '"+email+"' and password = '"+password +"'", function (err, result) {
});
第二個條件
databaseConnection.query("SELECT * FROM users where email = '"+email+"' and password = '"+password +"'", function (err, result) {
var arr = {email:"[email protected]", password:"};
return arr;
});
從passport.js
var LocalStrategy = require('passport-local').Strategy;
var FacebookStrategy = require('passport-facebook').Strategy;
var TwitterStrategy = require('passport-twitter').Strategy;
var configAuth = require('./auth');
module.exports = function(passport,databaseConnection) {
var usermodule = require('../models/user')(databaseConnection);
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
passport.use('local-login', new LocalStrategy({
usernameField : 'username',
passwordField : 'password',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done) { // callback with email and password from our form
var user={};
var result = usermodule.login(email,password);
console.log('usercraeted');
user["email"]=email;
user["status"]=true;
user["name"]="John Snow";
user["avatar"]="";
user["loginStatus"]=true;
return done(null, user);
user["msg"]="invalide email";
console.log("out");
return done(null, false,user["msg"]);
};
);
};
如何從數據庫返回結果? – SDA
@SyedDaniyalAsif,這段代碼在哪裏運行?你想在哪裏返回結果?發佈完整的代碼。 –
請檢查它 – SDA