feat: send proper response

This commit is contained in:
karishmas6
2024-09-25 16:16:49 +05:30
parent be9697b077
commit b55536d8fd

View File

@@ -67,7 +67,7 @@ router.get('/logout', async (req, res) => {
router.get('/current-user', async (req: AuthenticatedRequest, res) => { router.get('/current-user', async (req: AuthenticatedRequest, res) => {
try { try {
if (!req.user) { if (!req.user) {
return res.status(401).send('Unauthorized'); return res.status(401).json({ ok: false, error: 'Unauthorized' });
} }
const user = await User.findByPk(req.user.id, { const user = await User.findByPk(req.user.id, {
attributes: { exclude: ['password'] }, attributes: { exclude: ['password'] },
@@ -75,8 +75,8 @@ router.get('/current-user', async (req: AuthenticatedRequest, res) => {
if (!user) { if (!user) {
return res.status(404).json({ ok: false, error: 'User not found' }); return res.status(404).json({ ok: false, error: 'User not found' });
} }
return res.status(200).json({ ok: true }); return res.status(200).json({ ok: true, user: user });
} catch (error: any) { } catch (error: any) {
return res.status(500).send(`Could not fetch current user : ${error.message}.`); return res.status(500).json({ ok: false, error: `Could not fetch current user: ${error.message}` });
} }
}); });