javascript 用于社交身份验证的DEFAULT用户架构
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 用于社交身份验证的DEFAULT用户架构相关的知识,希望对你有一定的参考价值。
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const validator = require('validator');
const mongodbErrorHandler = require('mongoose-mongodb-errors');
const passportLocalMongoose = require('passport-local-mongoose');
const userSchema = new mongoose.Schema({
name: {
type: String,
unique: true,
lowercase: true,
trim: true
},
email: {
type: String,
unique: true,
lowercase: true,
trim: true,
validate: [validator.isEmail, 'Invalid email address!'],
required: 'Please enter an email address!'
},
google: {
id: String,
token: String,
email: String,
name: String
},
twitter: {
id: String,
token: String,
email: String,
name: String
},
facebook: {
id: String,
token: String,
email: String,
name: String
},
resetPasswordToken: String,
resetPasswordExpires: Date,
});
// add passport-local authentication methods to schema
userSchema.plugin(passportLocalMongoose, {
usernameField: 'email'
});
// mongodbErrorHandler beautifies errors
userSchema.plugin(mongodbErrorHandler);
module.exports = mongoose.model('User', userSchema);
以上是关于javascript 用于社交身份验证的DEFAULT用户架构的主要内容,如果未能解决你的问题,请参考以下文章