Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose');
- const bcrypt = require('bcryptjs');
- const UserSchema = new mongoose.Schema({
- name: {
- type: String,
- required: true
- },
- email: {
- type: String,
- unique: true,
- required: true,
- lowercase: true
- },
- password: {
- type: String,
- required: true,
- select: false
- },
- createAt: {
- type: Date,
- default: Date.now
- }
- })
- UserSchema.pre('save', async function (next) {
- const hash = await bcrypt.hash(this.password, 10);
- this.password = hash;
- next();
- })
- const User = mongoose.model('User', UserSchema);
- module.exports = User;
Add Comment
Please, Sign In to add comment