update logout route on delete-account

This commit is contained in:
HF 2022-06-20 23:27:27 +02:00
parent 725e23dbab
commit 28e812737d

View File

@ -1,11 +1,7 @@
/* /*
* request password change * request password change
* @flow
*/ */
import type { Request, Response } from 'express';
import { RegUser } from '../../../data/sql'; import { RegUser } from '../../../data/sql';
import { validatePassword } from '../../../utils/validation'; import { validatePassword } from '../../../utils/validation';
import { compareToHash } from '../../../utils/hash'; import { compareToHash } from '../../../utils/hash';
@ -19,7 +15,7 @@ function validate(password, gettext) {
return errors; return errors;
} }
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { password } = req.body; const { password } = req.body;
const { t, gettext } = req.ttag; const { t, gettext } = req.ttag;
const errors = await validate(password, gettext); const errors = await validate(password, gettext);
@ -50,10 +46,21 @@ export default async (req: Request, res: Response) => {
return; return;
} }
req.logout();
RegUser.destroy({ where: { id } });
res.json({ req.logout((err) => {
success: true, if (err) {
res.status(500);
res.json({
errors: [t`Server error when logging out.`],
});
return;
}
RegUser.destroy({ where: { id } });
res.status(200);
res.json({
success: true,
});
}); });
}; };