---
import { createCaller } from "#lib/caller";
import UserLayout from "../../layouts/UserLayout.astro";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
import DashboardModule from "#modules/Dashboard/DashboardModule.svelte";

const accessTokenValid = await validateAccessTokenServer(Astro);

if (!accessTokenValid) {
	return Astro.redirect("/auth/login")
}

const caller = createCaller(Astro);

const user = await caller.v1.benutzer.self(undefined);
const gebaeudeArray = await caller.v1.gebaeude.getMany({ limit: 5 });
---

<UserLayout title="Dashboard">
	<DashboardModule user={user} gebaeudeArray={gebaeudeArray} />
</UserLayout>