From 538bf59510f75b94c3f4f87b99a43aa7b2fad2c6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:51:55 +0530 Subject: [PATCH] feat: get user from req --- server/src/routes/proxy.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/src/routes/proxy.ts b/server/src/routes/proxy.ts index 13549f8d..eb2b89a4 100644 --- a/server/src/routes/proxy.ts +++ b/server/src/routes/proxy.ts @@ -13,15 +13,21 @@ router.post('/config', requireSignIn, async (req: AuthenticatedRequest, res: Res const { server_url, username, password } = req.body; try { - if (!server_url) { - return res.status(400).send('Proxy URL is required'); - } - const userId = 1; - const user = await User.findByPk(userId); + if (!req.user) { + return res.status(401).json({ ok: false, error: 'Unauthorized' }); + } + + const user = await User.findByPk(req.user.id, { + attributes: { exclude: ['password'] }, + }); if (!user) { - return res.status(404).send('User not found'); + return res.status(404).json({ message: 'User not found' }); + } + + if (!server_url) { + return res.status(400).send('Proxy URL is required'); } let hashedProxyUsername: string | null = null;