diff --git a/src/lib/components/common/classes.svelte b/src/lib/components/common/classes.svelte index e235e2e..220bb3d 100644 --- a/src/lib/components/common/classes.svelte +++ b/src/lib/components/common/classes.svelte @@ -15,7 +15,6 @@ export class AppSettingsObject { navbarTitle = ''; // for setting the title of the page - appLoaded = false; // for hiding the screen until hydration has completed sidebarDrawerOpen = false; // for determining if the sidebar is open when on a small screen toastAlerts = new SvelteMap(); // for adding or removing alerts apiTested = true; // used to hide the app if the api tests are failing diff --git a/src/lib/components/layout/auth-functions.svelte b/src/lib/components/layout/auth-functions.svelte deleted file mode 100644 index 9e5e72f..0000000 --- a/src/lib/components/layout/auth-functions.svelte +++ /dev/null @@ -1,30 +0,0 @@ - \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 148f4b0..3290c49 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -7,10 +7,10 @@ import { onMount } from 'svelte'; import { fade } from 'svelte/transition'; import '../app.css'; - import { checkAuth } from '$lib/components/layout/auth-functions.svelte'; let { children } = $props(); + let pageStatus = $state(''); - onMount(async () => { + onMount(() => { // monitor the persistent app store and read/write to local storage as required // load existing persistentAppSettings from localStorage let localStorageAppSettings = JSON.parse(localStorage.getItem('persistentAppSettings') || '{}') as PersistentAppSettingsObject; @@ -20,29 +20,11 @@ $effect(() => { localStorage.setItem('persistentAppSettings', JSON.stringify(persistentAppSettings)); }); - - - // populate any settings being passed through by url params - const urlParams = new URLSearchParams(window.location.search); - let headscaleApiKeyParam = urlParams.get('apikey'); - let headscaleUrlParam = urlParams.get('url'); - - if (headscaleApiKeyParam) { - persistentAppSettings.headscaleAPIKey = headscaleApiKeyParam; - } - if (headscaleUrlParam) { - persistentAppSettings.headscaleURL = headscaleUrlParam; - } - - // do an initial authentication check - await checkAuth(); - - // delay load until page is hydrated - appSettings.appLoaded = true; + pageStatus = 'loaded'; }); -{#if appSettings.appLoaded} +{#if pageStatus == 'loaded'}
@@ -56,11 +38,11 @@ {/each} - diff --git a/src/routes/login.html/+page.svelte b/src/routes/login.html/+page.svelte index 7b0ddf2..b1dd676 100644 --- a/src/routes/login.html/+page.svelte +++ b/src/routes/login.html/+page.svelte @@ -2,13 +2,16 @@ import { appSettings } from '$lib/components/common/state.svelte'; import { fade } from 'svelte/transition'; import { loginOrRegister } from '$lib/components/login/auth-functions.svelte'; + import { onMount } from 'svelte'; appSettings.navbarTitle = 'Login'; appSettings.sidebarDrawerOpen = false; - let loginType = $state('none'); - loginOrRegister().then(function (loginResult) { - loginType = loginResult; + + onMount(() => { + loginOrRegister().then(function (loginResult) { + loginType = loginResult; + }); }); diff --git a/src/routes/settings.html/+page.svelte b/src/routes/settings.html/+page.svelte index f144134..86961c3 100644 --- a/src/routes/settings.html/+page.svelte +++ b/src/routes/settings.html/+page.svelte @@ -2,6 +2,21 @@ import { appSettings } from '$lib/components/common/state.svelte'; import ServerSettings from '$lib/components/settings/server-settings.svelte'; import ThemeSettings from '$lib/components/settings/theme-settings.svelte'; + import { goto } from '$app/navigation'; + import { resolve } from '$app/paths'; + import { onMount } from 'svelte'; + + let pageStatus = $state('none'); + + onMount(() => { + if (!appSettings.pb.authStore.isValid) { + goto(resolve('/login.html')); + } else { + appSettings.navbarTitle = 'Settings'; + appSettings.sidebarDrawerOpen = false; + pageStatus = 'loaded'; + } + }); appSettings.navbarTitle = 'Settings'; appSettings.sidebarDrawerOpen = false; diff --git a/src/routes/users.html/+page.svelte b/src/routes/users.html/+page.svelte index fd3f40d..fe38dc8 100644 --- a/src/routes/users.html/+page.svelte +++ b/src/routes/users.html/+page.svelte @@ -1,11 +1,23 @@ -{#if appSettings.apiTested} +{#if pageStatus == 'loaded'} {/if} \ No newline at end of file diff --git a/svelte.config.js b/svelte.config.js index 4e24f16..72e10a9 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -22,6 +22,9 @@ const config = { } }, compilerOptions: { + experimental: { + async: true + }, runes: true } };