在Passport KeystoneJS中创建新用户时出现Mongoose ValidationError

时间:2014-11-23 15:17:38

标签: node.js oauth mongoose passport.js keystonejs

我在项目中使用Passport authentication plugin for KeystoneJS

如果用户帐户存在并且与所使用的社交网络绑定,那么一切都很有效。但是,在使用配置选项'auto create user': true创建新用户时,我最终会在oauth回调路由上出现500错误。日志说它是验证错误。

ValidationError: Validation failed 
  at model.Document.invalidate (/app/node_modules/keystone/node_modules/mongoose/lib/document.js:1021:32) 
  at /app/node_modules/keystone/node_modules/mongoose/lib/document.js:970:16 
  at validate (/app/node_modules/keystone/node_modules/mongoose/lib/schematype.js:610:7) 
  at /app/node_modules/keystone/node_modules/mongoose/lib/schematype.js:627:9 
  at Array.forEach (native) 
  at SchemaString.SchemaType.doValidate (/app/node_modules/keystone/node_modules/mongoose/lib/schematype.js:614:19) 
  at /app/node_modules/keystone/node_modules/mongoose/lib/document.js:968:9 
  at process._tickCallback (node.js:419:13)

导致这种情况的原因是什么?


修改

用户模型:

var keystone = require('keystone'),
Types = keystone.Field.Types,
social = require('keystone-social-login');

/**
 * User Model
 * ==========
 */

var User = new keystone.List('User');

User.add({
    name: { type: Types.Name, required: true, index: true },
    email: { type: Types.Email, initial: true, required: true, index: true },
    password: { type: Types.Password, initial: true, required: true }
}, 'Permissions', {
    userLevel: { type: Types.Select, options: 'user, business, admin', default: 'user', initial: true }
});

// Provide access to Keystone
User.schema.virtual('canAccessKeystone').get(function() {
    return this.userLevel === 'admin';
});


/**
 * Registration
 */

social.plugin(User);

User.defaultColumns = 'name, email, userLevel';
User.register();

0 个答案:

没有答案