18 lines
535 B
JavaScript
18 lines
535 B
JavaScript
![]() |
const mongoose = require('mongoose');
|
||
|
const bcrypt = require('bcrypt');
|
||
|
|
||
|
const admin = new mongoose.Schema({
|
||
|
username: { type: String, required: true, unique: true },
|
||
|
password: { type: String, required: true },
|
||
|
email: { type: String, required: true },
|
||
|
setupComplete: { type: Boolean, default: false }
|
||
|
});
|
||
|
|
||
|
admin.pre('save', async function(next) {
|
||
|
if (this.isModified('password')) {
|
||
|
this.password = await bcrypt.hash(this.password, 10);
|
||
|
}
|
||
|
next();
|
||
|
});
|
||
|
|
||
|
module.exports = mongoose.model('Admin', admin);
|