add action for deleting account
This commit is contained in:
parent
957cc8f38c
commit
9f89ba231a
18
src/routes/profile/+page.server.ts
Normal file
18
src/routes/profile/+page.server.ts
Normal 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;
|
|
@ -4,3 +4,7 @@
|
|||
|
||||
<h1>hi yess you need a profile</h1>
|
||||
<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>
|
||||
|
|
Loading…
Reference in a new issue