Account deletion endpoint

This commit is contained in:
Tom Moor
2018-07-07 17:38:22 -05:00
parent a049e0e9bc
commit 465f819c45
5 changed files with 121 additions and 10 deletions

View File

@ -164,4 +164,22 @@ router.post('user.activate', auth(), async ctx => {
};
});
router.post('user.delete', auth(), async ctx => {
const { confirmation } = ctx.body;
ctx.assertPresent(confirmation, 'confirmation is required');
const user = ctx.state.user;
authorize(user, 'delete', user);
try {
await user.destroy();
} catch (err) {
throw new ValidationError(err.message);
}
ctx.body = {
success: true,
};
});
export default router;