diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 230e2a5f..c33409c2 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -146,21 +146,20 @@ router.get('/api-key', requireSignIn, async (req: AuthenticatedRequest, res) => router.delete('/delete-api-key', requireSignIn, async (req, res) => { try { - const user = await User.findByPk(req.user.id, { raw: true }); - - if (!user) { - return res.status(404).json({ message: 'User not found' }); - } - - if (!user.api_key) { - return res.status(404).json({ message: 'API Key not found' }); - } - - await User.update({ api_key: null }, { where: { id: req.user.id } }); - - return res.status(200).json({ message: 'API Key deleted successfully' }); + const user = await User.findByPk(req.user.id, { raw: true }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + if (!user.api_key) { + return res.status(404).json({ message: 'API Key not found' }); + } + + await User.update({ api_key: null }, { where: { id: req.user.id } }); + + return res.status(200).json({ message: 'API Key deleted successfully' }); } catch (error: any) { - return res.status(500).json({ message: 'Error deleting API key', error: error.message }); + return res.status(500).json({ message: 'Error deleting API key', error: error.message }); } - }); - \ No newline at end of file +});