SHARE
TWEET

Untitled

a guest Apr 1st, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose = require('mongoose')
  2. const Schema = mongoose.Schema
  3. const bcrypt = require('bcryptjs')
  4.  
  5. const UserSchema = new Schema({
  6.   name: {
  7.     type: String,
  8.     require: true
  9.   },
  10.   email: {
  11.     type: String,
  12.     unique: true,
  13.     required: true,
  14.     lowercase: true
  15.   },
  16.   password: {
  17.     type: String,
  18.     required: true,
  19.     select: false
  20.   },
  21.   createdAt: {
  22.     type: Date,
  23.     default: Date.now
  24.   }
  25. })
  26.  
  27. UserSchema.pre('save', async function (next) {
  28.   const hash = await bcrypt.hash(this.password, 10)
  29.   this.password = hash
  30.   next()
  31. })
  32.  
  33. const User = mongoose.model('User', UserSchema)
  34. module.exports = User
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top