add action for deleting account

This commit is contained in:
Erin 2023-11-12 16:06:27 -05:00
parent 957cc8f38c
commit 9f89ba231a
2 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,18 @@
import {getDataSource} from '$lib/server/db';
import {User} from '$lib/server/entity/User';
import {getUserFromSessionID} from '$lib/server/sessionutil';
import {type Actions, redirect} from '@sveltejs/kit';
export const actions = {
async delete ({cookies}) {
const user = await getUserFromSessionID(cookies.get('sessionid'));
if (user) {
const dataSource = await getDataSource();
const usersRepo = dataSource.getRepository(User);
usersRepo.remove(user);
cookies.delete('sessionid');
}
throw redirect(302, '/');
},
} satisfies Actions;

View file

@ -4,3 +4,7 @@
<h1>hi yess you need a profile</h1> <h1>hi yess you need a profile</h1>
<p>i am still learning form shit but. soon</p> <p>i am still learning form shit but. soon</p>
<form method="POST" action="/profile?/delete">
<p>alternatively, you can <button>delete your account</button></p>
</form>