因为我还没有发现与dynamodb和护照相关的错误,但我真的想打开这篇文章。当我尝试使用我的节点脚本登录时,此错误会导致整个Express应用程序崩溃。
~/node_modules/aws-sdk/lib/request.js:31
throw err;
^
Error: Incorrect arguments
at Request.callListeners ~/node_modules/aws-sdk/lib/sequential_executor.js:107:43)
at Request.emit ~/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit ~/node_modules/aws-sdk/lib/request.js:673:14)
at Request.transition (~/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (~/node_modules/aws-sdk/lib/state_machine.js:14:12)
at ~/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (~/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (~/node_modules/aws-sdk/lib/request.js:675:12)
at Request.callListeners (~/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
at Request.emit (~node_modules/aws-sdk/lib/sequential_executor.js:77:10)
这是我认为查询导致错误的注册脚本:
const LocalStrategy = require("passport-local").Strategy;
const bCrypt = require("bcrypt-nodejs");
const AWS = require("aws-sdk");
const dynamodb = new AWS.DynamoDB({
apiVersion: "2012-08-10",
//testing purposes
"region": "us-west-2",
"accessKeyId": "abcde",
"secretAccessKey": "abcde",
"endpoint": "http://localhost:8001"
});
module.exports = function(passport) {
passport.use("login", new LocalStrategy({
passReqToCallback: true
},
function(req,username,password,done) {
var queryParams = {
TableName: "users",
KeyConditionExpression: "username = :user",
ExpressionAttributeValues: {
//username entered in jade form
":user":{"S":username}
}
};
//querying dynamodb for username
dynamodb.query(queryParams,
function(err,user) {
if(err) {
console.error(username);
console.error(err);
return done(err);
}
//if no users with said username in db
if(user.Count < 1) {
console.error("user: " + username + " not found in db");
return done(null, false, req.flash("message" , "user not found"));
}
//too many entries (admin's fault)
if(user.Count > 1){
console.error("error, more than one user with " + username + " in db");
return done(null,false,req.flash("message", "more than version of the username in the db"));
} else {
//only one user exists in db, query for username was successful
user.Items.forEach(function(item){
//checking if entered password is wrong
if(!isValidPassword(item.username, item.password)) {
console.error("invalid username - password combination");
return done(null,false,req.flash("message","invalid user-password combination"));
}
//passwortcheck wird gar nicht ausgeführt - query returnt noch nicht die richtigen Ergebnisse
//successful login - user and password match
console.log("login successful");
console.log(user.username); //undefined
console.log(user.password); //undefined
console.log(user);
//return user object for serialization
return done(null,user);
});
}
});
//passport serialization to support persitent login sessions
passport.serializeUser(function(user,done){
console.log("serializing user: " + user);
done(null, user.id);
});
passport.deserializeUser(function(id,done){
User.findById(id, function(err, user) {
console.log("deserializing user: " + user);
done(err,user);
});
});
}
));
var isValidPassword = function(user, password) {
return bCrypt.compareSync(password,user.password);
}
}