everytime i register with same email on register page it still record on my mongodb whereas i expect it to not recorded
i try to write unique:true on email var at User.js like this
import bcrypt from 'bcrypt';import { Schema, model, models } from "mongoose";const UserSchema = new Schema({ email: {type: String, required: true, unique: true}, password: { type: String, required: true, validate: pass => { if(!pass?.length || pass.length < 5){ new Error('password setidaknya harus 5 karakter'); return false; } }, },},{timestamps: true});UserSchema.post('validate', function (user){ const notHashedPassword = user.password; const salt = bcrypt.genSaltSync(10); user.password = bcrypt.hashSync(notHashedPassword, salt);})