aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/__layout.svelte
blob: 95b2e0c380405bfd7cc5df017a4e219a3cc61540 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<script>
	import '../app.css';
	import { onMount } from 'svelte';
	import { connect } from '$lib/socket';
	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);
	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>

{#if ready}
	<slot />
{/if}