diff options
| author | Adam Soltys <[email protected]> | 2022-07-30 09:47:08 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-07-30 09:47:08 -0700 |
| commit | 8acc59a86b6ec049dfe07f92fd19eeda726136f3 (patch) | |
| tree | 56c6506d19c38a59fba962c53a71526b3a1825b5 /src/routes/__layout.svelte | |
| parent | 1f8b1f52431dc7a95118b310dbca3a178d24614b (diff) | |
| download | coinos-ui-8acc59a86b6ec049dfe07f92fd19eeda726136f3.tar.gz coinos-ui-8acc59a86b6ec049dfe07f92fd19eeda726136f3.zip | |
logout function
Diffstat (limited to 'src/routes/__layout.svelte')
| -rw-r--r-- | src/routes/__layout.svelte | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 6562db18..c01dc848 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -2,12 +2,27 @@ import '../app.css'; import { onMount } from 'svelte'; import { connect } from '$lib/socket'; - import { token } from '$lib/store'; - import { session } from '$app/stores'; + import { user, token } from '$lib/store'; + import { page, session } from '$app/stores'; import { browser } from '$app/env'; + import { goto } from '$app/navigation'; browser && ($token ||= $session.token); - onMount(connect); + let protectedRoutes = [/receive/]; + let ready = false; + + onMount(() => { + if (protectedRoutes.find((p) => $page.url.pathname.match(p))) { + if (!$token) goto('/login'); + user.subscribe((u) => (ready = true)); + } else { + ready = true; + } + + connect(); + }); </script> -<slot /> +{#if ready} + <slot /> +{/if} |
