<script lang="ts">
	import '../app.css';
	import { page } from '$app/stores';
	import { stdb } from '$lib/spacetime';
	import { browser } from '$app/environment';

	let { children } = $props();

	// Connect to SpacetimeDB when authenticated and in browser
	$effect(() => {
		if (browser && $page.data.session?.user) {
			stdb.connect();
		}
		return () => {
			if (browser) stdb.disconnect();
		};
	});
</script>

{@render children()}
