From 73b84669bf091f2f96c3f8e583ba029ed6ba78a1 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Sat, 21 Jan 2023 19:07:53 +0100 Subject: [PATCH] feat: add endpoint for deleting user data --- src/routes/users/index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/routes/users/index.ts b/src/routes/users/index.ts index 888ff007f..8d4ede896 100644 --- a/src/routes/users/index.ts +++ b/src/routes/users/index.ts @@ -190,4 +190,23 @@ router.get('/debug/locals', RequireAuthentication, (_req, res) => { return res.json({ locals }); }); +router.post('/delete-account', RequireAuthentication, async (req, res) => { + const { owner } = res.locals; + if (!owner && req.body.confirmed === true) { + return res.status(400).json({}); + } + + await DB('access_tokens').where({ owner }).del(); + await DB('favorites').where({ owner }).del(); + await DB('jobs').where({ owner }).del(); + await DB('notion_tokens').where({ owner }).del(); + await DB('parser_rules').where({ owner }).del(); + await DB('patreon_tokens').where({ owner }).del(); + await DB('settings').where({ owner }).del(); + await DB('templates').where({ owner }).del(); + await DB('uploads').where({ owner }).del(); + await DB('users').where({ id: owner }).del(); + res.status(200).json({}); +}); + export default router;