From 377a55574daf9b134d5d2f37ba04075d4eea56d6 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 29 Jul 2024 23:04:52 +0200 Subject: [PATCH] clean code --- src/routes/+page.ts | 4 ++-- src/routes/home/+page.ts | 24 +++--------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/routes/+page.ts b/src/routes/+page.ts index 233345c3..bcc34086 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -4,9 +4,9 @@ import { redirect } from '@sveltejs/kit'; export const load = async ({parent}) => { - const data = await parent(); + const { user } = await parent(); - if (data?.user) { + if (user) { redirect(303, '/home'); } diff --git a/src/routes/home/+page.ts b/src/routes/home/+page.ts index 6be924fe..280735cf 100644 --- a/src/routes/home/+page.ts +++ b/src/routes/home/+page.ts @@ -1,16 +1,9 @@ -import { userRegion, getCache, setCache } from '$lib/store'; +import { getCache, setCache } from '$lib/store'; import defaultAvatar from '$lib/images/senator/default-avatar.png'; import { getPartyForPoliticians } from '$lib/utils'; import { redirect } from '@sveltejs/kit'; -const usRegion = ['cle1','iad1','pdx1','sfo1']; - -let apiURL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - - let images = {}; // Function to load images only when they are viewed async function loadImages() { @@ -30,22 +23,11 @@ async function loadImages() { } - -userRegion.subscribe(value => { - - if (usRegion.includes(value)) { - apiURL = import.meta.env.VITE_USEAST_API_URL; - } else { - apiURL = import.meta.env.VITE_EU_API_URL; - } -}); - - export const load = async ({ parent}) => { - const data = await parent(); + const { user, apiKey, apiURL } = await parent(); - if (!data?.user) { + if (!user) { redirect(303, '/'); }