我通过http://localhost:3000/auth/register注册一个简单的平均应用程序时遇到了主题错误,我只是使用mean init
命令创建的。 pbkdf2
或crypto
正在生成错误,我不知道在哪里寻找它。
我做了很多不同的事情,比如清除npm缓存,使用npm等重新安装。请帮帮我。以下是一些更多信息。
Mean --version: 0.12.15
npm --version: 5.0.3
node --version: v8.1.0
bower --version: 1.8.0
gulp --version: CLI and Local: 3.9.1
model.UserSchema.methods.hashPassword
的代码(D:\ Projects \ Mean \ CampaignBuilder \ node_modules \ meanio-users \ server \ models \ user.js)
/**
* Hash password
*
* @param {String} password
* @return {String}
* @api public
*/
UserSchema.methods.hashPassword = function(password) {
if (!password || !this.salt) return '';
var salt = new Buffer(this.salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
};
注册页面调用http://localhost:3000/api/register,然后生成500 Internal Server Error
。
Firefox正在显示以下回复:
TypeError: The "digest" argument is required and must not be undefined
at pbkdf2 (crypto.js:635:11)
at Object.exports.pbkdf2Sync (crypto.js:628:10)
at model.UserSchema.methods.hashPassword (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js:165:17)
at model.<anonymous> (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js:94:31)
at VirtualType.applySetters (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\virtualtype.js:94:25)
at model.Document.set (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:656:12)
at model._handleIndex (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:587:14)
at model.Document.set (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:547:24)
at model.Document (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:71:12)
at model.Model (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\model.js:46:12)
at new model (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\model.js:3621:13)
at create (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\controllers\users.js:86:24)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:281:22
at Function.process_params (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:335:12)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:275:10)
at loadUser (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\controllers\users.js:202:24)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:317:13)
at D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:335:12)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:275:10)
at D:\Projects\Mean\CampaignBuilder\node_modules\connect-modrewrite\index.js:129:7
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:317:13)
答案 0 :(得分:24)
根据crypto.pbkdf2Sync
方法,您缺少最后一个参数digest
,因此显示错误。
通过进一步调查,您可以看到在节点v6.0中需要摘要参数。
之前的默认值似乎是'sha1'
。