From b55536d8fd0919d0e1ce5377238f0b3521973311 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 25 Sep 2024 16:16:49 +0530 Subject: [PATCH] feat: send proper response --- server/src/routes/auth.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 865e1448..8622a72d 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -67,7 +67,7 @@ router.get('/logout', async (req, res) => { router.get('/current-user', async (req: AuthenticatedRequest, res) => { try { 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, { attributes: { exclude: ['password'] }, @@ -75,8 +75,8 @@ router.get('/current-user', async (req: AuthenticatedRequest, res) => { if (!user) { 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) { - 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}` }); } }); \ No newline at end of file