From 72a8a40b33db3707bc3be96af27abfb29110124f Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Thu, 1 Aug 2024 22:25:00 +0200 Subject: [PATCH] bugfixing --- src/routes/+page.server.ts | 25 ------------------------- src/routes/home/+page.ts | 11 +++++------ 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 4b8bbdbf..52e80c10 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -3,31 +3,6 @@ import { validateData } from "$lib/utils"; import { loginUserSchema, registerUserSchema } from "$lib/schemas"; -export const load = async () => { - - const apiKey = import.meta.env.VITE_LEMON_SQUEEZY_API_KEY; - - const getLTDCount = async () => { - // make the POST request to the endpoint - const response = await fetch('https://api.lemonsqueezy.com/v1/order-items?page[size]=100', { - headers: { - 'Accept': 'application/vnd.api+json', - 'Content-Type': 'application/vnd.api+json', - 'Authorization': `Bearer ${apiKey}` - } - }); - const output = await response.json(); - const filteredData = output?.data?.filter(item => item?.attributes?.product_name === 'Pro Subscription (Life Time Access)'); - const count = filteredData?.length || 0; - - return count; - }; - - return { - getLTDCount: await getLTDCount(), - }; - }; - async function checkDisposableEmail(email) { const url = `https://disposable.debounce.io/?email=${encodeURIComponent(email)}`; diff --git a/src/routes/home/+page.ts b/src/routes/home/+page.ts index e35bfe5c..a648317d 100644 --- a/src/routes/home/+page.ts +++ b/src/routes/home/+page.ts @@ -2,22 +2,21 @@ import { getCache, setCache } from '$lib/store'; import { redirect } from '@sveltejs/kit'; -export const load = async ({ parent}) => { +export const load = async ({parent}) => { const { user, apiKey, apiURL } = await parent(); + if (!user) { redirect(303, '/'); } - const getDashboard = async () => { - let output; // Get cached data for the specific tickerID const cachedData = getCache('', 'getDashboard'); if (cachedData) { - output = cachedData; + return cachedData; } else { const response = await fetch(apiURL + '/dashboard-info', { @@ -27,10 +26,10 @@ export const load = async ({ parent}) => { }, }); - output = await response.json(); + const output = await response?.json(); setCache('', output, 'getDashboard'); + return output; } - return output; }; // Make sure to return a promise