我有这个代码,它在我的开发计算机上工作得很好,但在服务器上却没有.
db.admin.verify([req.body.username]).then(function(data){
if (data[0].length == 0){ //if there is no user with that username
console.log("bad username");
res.status(401).send('Incorrect username or password');
}
var creds = data[0][0];
return myCrypt.pbkdf2(req.body.password, creds.salt).then(function(key){
if (creds.password === key.toString('base64')){ //correct password
console.log("correct pw");
return db.admin.getUser([req.body.username])
} else {
console.log("bad pw");
res.status(401).send('Incorrect password or username');
}
});
}).then(function(dbData){
var user = dbData[0][0];
var profile = {
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
username: user.username,
type: user.type,
id: user.adminId
};
var token = jwt.sign(profile, 'secrets');
res.json({token:token, user: profile});
}).catch(function(err){ …Run Code Online (Sandbox Code Playgroud)