Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose')
- const Schema = mongoose.Schema
- const bcrypt = require('bcryptjs')
- const UserSchema = new Schema({
- name: {
- type: String,
- require: true
- },
- email: {
- type: String,
- unique: true,
- required: true,
- lowercase: true
- },
- password: {
- type: String,
- required: true,
- select: false
- },
- createdAt: {
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement