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

2. إضافة مسار الدخول (Login Route):

// 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: 'خطأ في الدخول' });
    }
});

Sep 27, 2024
Read More