feat: use authenticatedReq to query db

This commit is contained in:
amhsirak
2025-01-29 15:15:53 +05:30
parent 2077e2a89f
commit b95e8d18ef

View File

@@ -22,7 +22,7 @@ router.post('/config', requireSignIn, async (req: Request, res: Response) => {
return res.status(401).json({ ok: false, error: 'Unauthorized' }); return res.status(401).json({ ok: false, error: 'Unauthorized' });
} }
const user = await User.findByPk(req.user.id, { const user = await User.findByPk(authenticatedReq.user.id, {
attributes: { exclude: ['password'] }, attributes: { exclude: ['password'] },
}); });
@@ -65,7 +65,7 @@ router.get('/test', requireSignIn, async (req: Request, res: Response) => {
return res.status(401).json({ ok: false, error: 'Unauthorized' }); return res.status(401).json({ ok: false, error: 'Unauthorized' });
} }
const user = await User.findByPk(req.user.id, { const user = await User.findByPk(authenticatedReq.user.id, {
attributes: ['proxy_url', 'proxy_username', 'proxy_password'], attributes: ['proxy_url', 'proxy_username', 'proxy_password'],
raw: true raw: true
}); });
@@ -107,7 +107,7 @@ router.get('/config', requireSignIn, async (req: Request, res: Response) => {
return res.status(401).json({ ok: false, error: 'Unauthorized' }); return res.status(401).json({ ok: false, error: 'Unauthorized' });
} }
const user = await User.findByPk(req.user.id, { const user = await User.findByPk(authenticatedReq.user.id, {
attributes: ['proxy_url', 'proxy_username', 'proxy_password'], attributes: ['proxy_url', 'proxy_username', 'proxy_password'],
raw: true, raw: true,
}); });
@@ -134,7 +134,7 @@ router.delete('/config', requireSignIn, async (req: Request, res: Response) => {
return res.status(401).json({ ok: false, error: 'Unauthorized' }); return res.status(401).json({ ok: false, error: 'Unauthorized' });
} }
const user = await User.findByPk(req.user.id); const user = await User.findByPk(authenticatedReq.user.id);
if (!user) { if (!user) {
return res.status(404).json({ message: 'User not found' }); return res.status(404).json({ message: 'User not found' });