diff --git a/pages/[slug].vue b/pages/[slug].vue index 8e20477..17cb208 100644 --- a/pages/[slug].vue +++ b/pages/[slug].vue @@ -20,7 +20,7 @@ Log In @@ -72,7 +72,7 @@ Log In @@ -204,7 +204,7 @@

Want to take notes?

Log in or create an account to save your sermon notes!

Log In diff --git a/pages/login.vue b/pages/login.vue index 8f60c7c..dc9e75b 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -222,7 +222,10 @@ async function handleLogin() { }) if (response.success) { - await navigateTo('/') + // Check if there's a redirect parameter + const route = useRoute() + const redirect = route.query.redirect as string + await navigateTo(redirect || '/') } } catch (e: any) { error.value = e.data?.message || 'Invalid credentials' @@ -261,7 +264,10 @@ async function handleRegister() { }) if (response.success) { - await navigateTo('/') + // Check if there's a redirect parameter + const route = useRoute() + const redirect = route.query.redirect as string + await navigateTo(redirect || '/') } } catch (e: any) { error.value = e.data?.message || 'Registration failed' diff --git a/pages/profile.vue b/pages/profile.vue index 04fd946..967417f 100644 --- a/pages/profile.vue +++ b/pages/profile.vue @@ -191,6 +191,58 @@ + + +
+

Delete Profile

+

+ ⚠️ Warning: Deleting your profile will permanently remove your account and all sermon notes that you haven't emailed or downloaded. This action cannot be undone. +

+ +
+ + + +
+
+

Confirm Profile Deletion

+

+ Are you absolutely sure you want to delete your profile? This will: +

+
    +
  • Permanently delete your account
  • +
  • Remove all your sermon notes
  • +
  • Cannot be undone
  • +
+

+ Make sure you have emailed or downloaded any notes you want to keep! +

+
+ + +
+
@@ -219,6 +271,8 @@ const passwords = ref({ const error = ref('') const success = ref('') const loading = ref(false) +const showDeleteConfirmation = ref(false) +const deleteLoading = ref(false) const passwordRequirements = computed(() => ({ minLength: passwords.value.new.length >= 8, @@ -312,6 +366,24 @@ async function handleLogout() { await navigateTo('/login') } +async function handleDeleteProfile() { + deleteLoading.value = true + + try { + await $fetch('/api/profile/delete', { + method: 'DELETE' + }) + + // Redirect to home page after successful deletion + await navigateTo('/') + } catch (e: any) { + error.value = e.data?.message || 'Failed to delete profile' + showDeleteConfirmation.value = false + } finally { + deleteLoading.value = false + } +} + onMounted(() => { loadProfile() }) diff --git a/server/api/profile/delete.delete.ts b/server/api/profile/delete.delete.ts new file mode 100644 index 0000000..103287f --- /dev/null +++ b/server/api/profile/delete.delete.ts @@ -0,0 +1,33 @@ +import { getDb } from '~/server/utils/database' +import { requireAuth } from '~/server/utils/auth' + +export default defineEventHandler(async (event) => { + const user = await requireAuth(event) + + const db = getDb() + + try { + // Delete user's notes first (foreign key constraint) + db.prepare('DELETE FROM notes WHERE user_id = ?').run(user.id) + + // Delete user's sessions + db.prepare('DELETE FROM sessions WHERE username = ?').run(user.username) + + // Delete the user + db.prepare('DELETE FROM users WHERE id = ?').run(user.id) + + // Clear the auth cookie + deleteCookie(event, 'session_token') + + return { + success: true, + message: 'Profile deleted successfully' + } + } catch (error) { + console.error('Error deleting profile:', error) + throw createError({ + statusCode: 500, + message: 'Failed to delete profile' + }) + } +})