Skip to content

Commit 3ac1572

Browse files
committed
block dev users
1 parent ff7c6e3 commit 3ac1572

2 files changed

Lines changed: 32 additions & 15 deletions

File tree

‎apps/codingcatdev/src/routes/(content-single)/course/[slug]/lesson/[lessonSlug]/+page.server.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { env } from '$env/dynamic/private';
12
import { getLessonFromCourseSlug } from '$lib/server/content';
23
import { db } from '$lib/server/firebase';
34
import { ContentType } from '$lib/types';
@@ -20,24 +21,38 @@ export const load = (async ({ params, parent, url }) => {
2021
throw redirect(307, `/login?redirectTo=${url.pathname}`);
2122
}
2223

23-
const snapshot = await db.collection('stripe-products').where('active', '==', true).get();
24-
const products = [];
24+
let allowedPast = true;
2525

26-
for (const doc of snapshot.docs) {
27-
const priceSnapshot = await doc.ref.collection('prices').where('active', '==', true).get();
26+
if (env.VERCEL_ENV !== "production") {
27+
const doc = await db.collection('admins').doc(user.uid).get();
28+
allowedPast = doc.exists;
29+
}
30+
31+
if (!user?.stripeRole && allowedPast) {
32+
const snapshot = await db.collection('stripe-products').where('active', '==', true).get();
33+
const products = [];
2834

29-
for (const price of priceSnapshot.docs) {
30-
products.push({
31-
id: doc.id,
32-
...doc.data(),
33-
price: price.id
34-
})
35+
for (const doc of snapshot.docs) {
36+
const priceSnapshot = await doc.ref.collection('prices').where('active', '==', true).get();
37+
38+
for (const price of priceSnapshot.docs) {
39+
products.push({
40+
id: doc.id,
41+
...doc.data(),
42+
price: price.id
43+
})
44+
}
3545
}
46+
47+
return {
48+
products,
49+
locked: content?.locked,
50+
title: content?.title
51+
};
3652
}
3753

3854
return {
3955
contentType,
40-
content,
41-
products
56+
content
4257
};
4358
});

‎apps/codingcatdev/src/routes/(content-single)/course/[slug]/lesson/[lessonSlug]/+page.svelte‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
export let data: PageData;
77
</script>
88

9-
{#if data.content.locked && !data?.user?.stripeRole}
9+
{#if data.locked && data.products}
1010
<section class="flex flex-col justify-center mt-8 items-center p-2">
1111
<div class="flex flex-col items-center gap-8">
1212
<div class="font-bold flex flex-col gap-2 max-w-4xl">
1313
<span class="text-3xl">You have reached a locked lesson.</span>
14-
<div class="text-primary-500 text-2xl">{data.content.title}</div>
14+
<div class="text-primary-500 text-2xl">{data.title}</div>
1515
Select the button below to add a Pro membership to your account.
1616
</div>
1717
<ProButton products={data.products} uid={data.user?.uid} />
1818
</div>
1919
</section>
20-
{:else}
20+
{:else if data.content}
2121
<Lesson {data} />
22+
{:else}
23+
Nice find, we are totally missing something!
2224
{/if}

0 commit comments

Comments
 (0)