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

// Login user
router.post('/login', async (req, res) => {
    const { email, password } = req.body;

    try {
        const user = await User.findOne({ email });
        if (!user) return res.status(400).json({ message: 'المستخدم غير موجود' });

        const isMatch = await bcrypt.compare(password, user.password);
        if (!isMatch) return res.status(400).json({ message: 'كلمة المرور غير صحيحة' });

        const token = jwt.sign({ id: user._id }, process.env.JWT_SECRET, { expiresIn: '1h' });
        res.json({ token });
    } catch (error) {
        res.status(500).json({ message: 'خطأ في الدخول' });
    }
});
   cd backend
   node server.js

Sep 27, 2024
Read More