mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-15 06:09:44 -06:00
45 lines
877 B
JavaScript
45 lines
877 B
JavaScript
const mongoose = require('mongoose')
|
|
const bcrypt = require('bcrypt')
|
|
|
|
const UserSchema = mongoose.Schema({
|
|
username: {
|
|
type: String
|
|
},
|
|
email: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
password: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
profilePicUrl: {
|
|
type: String
|
|
},
|
|
isActive: {
|
|
type: Boolean,
|
|
default: true
|
|
},
|
|
isVerified: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
updated_at: {
|
|
type: Date,
|
|
default: Date.now
|
|
},
|
|
created_at: {
|
|
type: Date,
|
|
default: Date.now
|
|
}
|
|
})
|
|
|
|
UserSchema.pre('save', async function (next) {
|
|
if (!this.isModified('password')) {
|
|
next()
|
|
}
|
|
const salt = bcrypt.genSalt(10);
|
|
this.password = await bcrypt.hash(this.password, salt);
|
|
})
|
|
|
|
module.exports = mongoose.model('User',UserSchema) |