16 lines
695 B
TypeScript
16 lines
695 B
TypeScript
|
|
// Delete the account and every project stored with it.
|
||
|
|
export default defineEventHandler(async event => {
|
||
|
|
rateLimit(event, 'login', 20, 10 * 60_000)
|
||
|
|
const user = await requireUser(event)
|
||
|
|
const body = await readBody<{ password?: unknown }>(event)
|
||
|
|
if (typeof body?.password !== 'string' || !(await verifyPassword(body.password, user))) {
|
||
|
|
throw createError({ statusCode: 403, message: 'The password is not right' })
|
||
|
|
}
|
||
|
|
await withLock(user.id, () => deleteAccountData(user.id))
|
||
|
|
await endAllSessions(user.id)
|
||
|
|
await users().removeItem(emailKey(user.email))
|
||
|
|
await users().removeItem(`user:${user.id}`)
|
||
|
|
deleteCookie(event, SESSION_COOKIE, { path: '/' })
|
||
|
|
return { ok: true }
|
||
|
|
})
|