Skip to content

Commit

Permalink
feat: add endpoint for deleting user data
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Jan 21, 2023
1 parent 629c9ad commit 73b8466
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/routes/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 73b8466

Please sign in to comment.