-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add button to delete all user data.
- Loading branch information
Showing
6 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/routes/(app)/[username]/components/DeleteProfileModal.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts"> | ||
import { getModalStore } from '@skeletonlabs/skeleton'; | ||
import { page } from '$app/stores'; | ||
import { goto } from '$app/navigation'; | ||
const modalStore = getModalStore(); | ||
let username = $state(''); | ||
async function deleteProfile() { | ||
await fetch(`/${$page.params.username}/settings/deleteProfile`, { | ||
method: 'post' | ||
}); | ||
await goto('/claim-username', { invalidateAll: true, replaceState: true }); | ||
modalStore.close(); | ||
} | ||
</script> | ||
|
||
{#if $modalStore[0]} | ||
<div class="card flex flex-col justify-between space-y-4 p-4 shadow-xl"> | ||
<div> | ||
<header class="text-2xl font-bold">Delete Profile Data</header> | ||
|
||
<section class="p-2"> | ||
<div class="prose prose-invert"> | ||
<p>Are you sure that you want to delete all of your profile data permanently?</p> | ||
<p>Type your full username to confirm deletion.</p> | ||
</div> | ||
|
||
<div class="my-2 flex flex-col gap-2"> | ||
<input class="input" bind:value={username} placeholder={$page.params.username} /> | ||
|
||
<button | ||
class="variant-ghost-error btn" | ||
disabled={username != $page.params.username} | ||
onclick={deleteProfile} | ||
> | ||
Delete | ||
</button> | ||
</div> | ||
</section> | ||
</div> | ||
|
||
<button class="variant-ghost btn" onclick={() => modalStore.close()}> Cancel </button> | ||
</div> | ||
{/if} |
22 changes: 22 additions & 0 deletions
22
src/routes/(app)/[username]/settings/deleteProfile/+server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { billing } from '$lib/billing'; | ||
import { deleteAllProfileDataById as deleteAllUserDataById } from '$lib/leaf/profile'; | ||
import { getSession } from '$lib/rauthy/server'; | ||
import { usernames } from '$lib/usernames'; | ||
import { type RequestHandler, error } from '@sveltejs/kit'; | ||
|
||
export const POST: RequestHandler = async ({ fetch, request }) => { | ||
const { sessionInfo } = await getSession(fetch, request); | ||
if (!sessionInfo) return error(404, 'Unauthorized'); | ||
|
||
// Cancel any billing subscription that might exist | ||
try { | ||
await billing.cancelBillingSubscription(sessionInfo.user_id); | ||
} catch (_) {} | ||
|
||
// Delete all user entities | ||
await deleteAllUserDataById(sessionInfo.user_id); | ||
const username = await usernames.getByRauthyId(sessionInfo.user_id); | ||
if (username) await usernames.unset(username); | ||
|
||
return new Response(); | ||
}; |