Skip to content

Commit e662c57

Browse files
committed
fix: free access and subs updates now use service role
- subscriptions and free access was showing the expired ones, not the ones still running
1 parent cdac0f8 commit e662c57

File tree

7 files changed

+13
-42
lines changed

7 files changed

+13
-42
lines changed

src/app.html

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,8 @@
55
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
%sveltekit.head%
8-
<style>
9-
.animate-gradient {
10-
background-size: 900%;
11-
-webkit-animation: animatedgradient 300s ease infinite alternate;
12-
-moz-animation: animatedgradient 300s ease infinite alternate;
13-
animation: animatedgradient 300s ease infinite alternate;
14-
}
15-
16-
@keyframes animatedgradient {
17-
0% {
18-
background-position: 100% 50%;
19-
}
20-
50% {
21-
background-position: 10% 50%;
22-
}
23-
100% {
24-
background-position: 100% 50%;
25-
}
26-
}
27-
</style>
288
</head>
29-
<body
30-
data-sveltekit-preload-data="hover"
31-
data-theme=""
32-
class="animate-gradient bg-gradient-to-br from-secondary-400-600 via-surface-200-800 via-10% to-surface-50-950 to-50%"
33-
>
9+
<body data-sveltekit-preload-data="hover" data-theme="">
3410
<div style="display: contents">%sveltekit.body%</div>
3511
</body>
3612
</html>

src/hooks.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const authGuard: Handle = async ({ event, resolve }) => {
105105
.from("subscriptions")
106106
.select("id, product, price, date_start, date_end, cancel, disabled")
107107
.eq("user_id", user.id)
108-
.lte("date_end", now)
108+
.gte("date_end", now)
109109

110110
if (err) return []
111111
return data
@@ -118,7 +118,7 @@ const authGuard: Handle = async ({ event, resolve }) => {
118118
.from("free_access")
119119
.select("id, product, date_start, date_end")
120120
.eq("user_id", user.id)
121-
.lte("date_end", now)
121+
.gte("date_end", now)
122122

123123
if (err) return []
124124
return data

src/lib/server/supabase.server.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,17 @@ export async function getPrivateProfile(id: string) {
8787
return data
8888
}
8989

90-
export async function addFreeAccess(
91-
supabase: SupabaseClient,
92-
user_id: string,
93-
product: string,
94-
date_end: string
95-
) {
96-
const { error: err } = await supabase
90+
export async function addFreeAccess(user_id: string, product: string, date_end: string) {
91+
const { error: err } = await supabaseAdmin
9792
.schema("profiles")
9893
.from("free_access")
9994
.insert({ product, user_id, date_end })
10095

10196
return err
10297
}
10398

104-
export async function cancelFreeAccess(supabase: SupabaseClient, id: string, product: string) {
105-
const { error: err } = await supabase
99+
export async function cancelFreeAccess(id: string, product: string) {
100+
const { error: err } = await supabaseAdmin
106101
.schema("profiles")
107102
.from("free_access")
108103
.delete()

src/routes/dashboard/[slug]/FreeAccessViewer.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
class="max-h-[95%] w-[95%] max-w-fit space-y-4 overflow-y-auto card bg-surface-100-900 p-4 shadow-xl"
5656
>
5757
<Dialog.Title class="flex flex-col justify-between text-2xl font-bold">
58-
<h1 class="my-4 flex flex-col gap-4 text-lg lg:flex-row lg:h4">{name} subscriptions</h1>
58+
<h1 class="my-4 flex flex-col gap-4 text-lg lg:flex-row lg:h4">{name} Free Access</h1>
5959
<h2>Total: {count}</h2>
6060
</Dialog.Title>
6161
<Dialog.Description>

src/routes/dashboard/[slug]/SubscriptionViewer.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
>
102102
<Dialog.Title class="flex flex-col justify-between text-2xl font-bold">
103103
<h1 class="my-4 text-center text-lg lg:h4">
104-
{name} subscriptions
104+
{name} Subscriptions
105105
</h1>
106106
<h2 class="my-4 text-center">Total subscriptions: {count}</h2>
107107
<div class="my-4 flex justify-evenly gap-2 text-sm">

src/routes/dashboard/[slug]/bundles/+page.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export const actions = {
294294

295295
const date_end = new Date(date_end_str).toISOString().toLocaleString()
296296

297-
const err = await addFreeAccess(supabaseServer, id, product, date_end)
297+
const err = await addFreeAccess(id, product, date_end)
298298

299299
if (err) error(403, formatError(err))
300300

@@ -323,7 +323,7 @@ export const actions = {
323323
if (!id) error(403, "User ID not specified.")
324324
if (!UUID_V4_REGEX.test(id)) error(403, "User ID is not a valid UUID.")
325325

326-
const err = await cancelFreeAccess(supabaseServer, id, product)
326+
const err = await cancelFreeAccess(id, product)
327327
if (err) error(403, formatError(err))
328328

329329
return

src/routes/dashboard/[slug]/scripts/+page.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export const actions = {
283283

284284
const date_end = new Date(date_end_str).toISOString().toLocaleString()
285285

286-
const err = await addFreeAccess(supabaseServer, id, product, date_end)
286+
const err = await addFreeAccess(id, product, date_end)
287287

288288
if (err) error(403, formatError(err))
289289

@@ -312,7 +312,7 @@ export const actions = {
312312
if (!id) error(403, "User ID not specified.")
313313
if (!UUID_V4_REGEX.test(id)) error(403, "User ID is not a valid UUID.")
314314

315-
const err = await cancelFreeAccess(supabaseServer, id, product)
315+
const err = await cancelFreeAccess(id, product)
316316
if (err) error(403, formatError(err))
317317

318318
return

0 commit comments

Comments
 (0)