<script lang="ts">
	import { getContext, onMount } from 'svelte';
	import { auth } from '$lib/stores';
	import LoginModal from '$lib/components/LoginModal.svelte';

	const { open } = getContext('simple-modal');

	const goHome = () => {
		open(LoginModal);
		window.location.href = '/';
	};

	onMount(() => {
		auth.subscribe((auth) => {
			if (!auth.loggedIn()) {
				goHome();
			}
		});
	});
</script>

<slot />
