DeveloperBreeze

تطبيق ويب كامل Development Tutorials, Guides & Insights

Unlock 1+ expert-curated تطبيق ويب كامل tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your تطبيق ويب كامل skills on DeveloperBreeze.

Tutorial
javascript

بناء تطبيق ويب متقدم باستخدام React.js وNode.js

داخل مجلد models، أنشئ ملفًا يسمى User.js:

const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const UserSchema = new mongoose.Schema({
    username: {
        type: String,
        required: true,
        unique: true
    },
    email: {
        type: String,
        required: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    }
});

// Hash the password before saving
UserSchema.pre('save', async function (next) {
    if (!this.isModified('password')) return next();
    const salt = await bcrypt.genSalt(10);
    this.password = await bcrypt.hash(this.password, salt);
    next();
});

module.exports = mongoose.model('User', UserSchema);

Sep 27, 2024
Read More