Quantcast
Channel: Active questions tagged mongodb-atlas - Stack Overflow
Viewing all articles
Browse latest Browse all 296

email duplicates on mongodb when hit register button on register page

$
0
0

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);})

Viewing all articles
Browse latest Browse all 296

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>