feat: return error if !user

This commit is contained in:
karishmas6
2024-09-25 15:59:33 +05:30
parent 366fb604f6
commit ce7291e048

View File

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