From 8612c4c64718c2a7eda3cd998071fde8b0321e0a Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 12 Aug 2026 21:32:24 +0200 Subject: [PATCH] feat: add unsubscribe button --- src/pages/account/upgrade.vue | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/pages/account/upgrade.vue b/src/pages/account/upgrade.vue index f9f74ba..98c4f2b 100644 --- a/src/pages/account/upgrade.vue +++ b/src/pages/account/upgrade.vue @@ -6,8 +6,21 @@ definePageMeta({ }); const { data: tierData } = await useApiFetch('/api/account/tiers'); +const { data: profile } = await useApiFetch('/api/auth/me'); const sortedTiers = computed(() => [...tierData.value?.tiers ?? []].sort((a, b) => a.tierLevel - b.tierLevel)); +async function unsubscribe() { + try { + await apiFetch('/api/account/unsubscribe', { + method: 'POST' + }); + await navigateTo('/account'); + } catch (error: unknown) { + const err = getApiError(error); + alert(err.code); + } +} + async function checkout(priceId: string) { try { const result = await apiFetch('/api/account/checkout', { @@ -22,6 +35,10 @@ async function checkout(priceId: string) { alert(err.code); } } + +function hasSubscription(priceId: string) { + return profile.value?.stripeTier && priceId === profile.value.stripeTier.priceId; +}