veltrixcode commited on
Commit
a0ac627
·
verified ·
1 Parent(s): aa7dcdc

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +3 -1
server.js CHANGED
@@ -403,6 +403,8 @@ app.get('/api/messages/:userId', checkOtpAuth, async (req, res) => {
403
  const userEmail = req.headers['x-user-email'];
404
  try {
405
  const db = await getSecondaryDb();
 
 
406
  // Allow legacy numeric id or ObjectId string
407
  const userIdStr = userId.toString();
408
  const userIdObj = ObjectId.isValid(userIdStr) ? new ObjectId(userIdStr) : userIdStr;
@@ -413,7 +415,7 @@ app.get('/api/messages/:userId', checkOtpAuth, async (req, res) => {
413
  res.json({ success: true, messages });
414
  } catch (error) {
415
  console.error('Error fetching messages:', error);
416
- res.status(500).json({ success: false, error: 'Failed to fetch messages' });
417
  }
418
  });
419
 
 
403
  const userEmail = req.headers['x-user-email'];
404
  try {
405
  const db = await getSecondaryDb();
406
+ const mainDb = await getDb();
407
+ const user = await mainDb.collection('users').findOne({ email: userEmail });
408
  // Allow legacy numeric id or ObjectId string
409
  const userIdStr = userId.toString();
410
  const userIdObj = ObjectId.isValid(userIdStr) ? new ObjectId(userIdStr) : userIdStr;
 
415
  res.json({ success: true, messages });
416
  } catch (error) {
417
  console.error('Error fetching messages:', error);
418
+ res.status(500).json({ success: false, error: 'Failed to fetch messages', details: error.message });
419
  }
420
  });
421