我正在使用带有护照的 MEAN 堆栈和 Passport-Local-Mongoose 插件。但是,每当我更新用户记录的用户名时,我都会退出当前会话。使用 Passport-Local-Mongoose 更新用户名的正确方法是什么?
// Update User -- Tied to Usernames or will log out
exports.update = function(req, res) {
user = req.user;
user = _.extend(user, req.body);
user.save(function(err, user) {
if(err) {
console.log(err);
// Error handling for uniqueness violations
if (err.code === 11001) {
if (err.err.indexOf("email") != -1) {
return next(new Error("Email Address Already In Use"));
} else if (err.err.indexOf("username") != -1) {
return next(new Error("Username Already In Use"));
}
}
};
});
};