এই পর্বে আমরা আমাদের ইউজারকে তার প্রোফাইল আপডেট করার সুযোগ দেব।
routes.js
// Update user profile
router.put('/profile-update', verifyToken, async (req, res) => {
try {
// Get the user ID from the token
const userId = req.user._id;
// Retrieve the user from the database
const user = await User.findById(userId);
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
// Update user profile fields
user.username = req.body.username || user.username;
user.email = req.body.email || user.email;
// Add additional fields for preferences or contact information
// Save the updated user profile
await user.save();
res.json({ message: 'Profile updated successfully' });
} catch (error) {
res.status(500).json({ message: error.message });
}
});