<script lang="ts">
	import userstore from '$lib/userstore';
	import { onMount } from 'svelte';

	$: loginRendered = false;

	onMount(async () => {
		try {
			await userstore.loginFromStorage();
			loginRendered = true;
		} catch (error) {
			console.log(error);
			userstore.logout();
			location.replace(`../login`);
		}
	});
</script>

{#if loginRendered}
	<slot />
{:else}
	<div class="mx-auto mt-20">
        <h1 class="block text-center text-2xl font-bold text-gray-800 dark:text-white">Lade Anmeldedaten...</h1>
    </div>
{/if}
