src/pages/Home.svelte (view raw)
1<script lang="ts">
2 import {
3 getDefaultSession,
4 handleIncomingRedirect,
5 fetch,
6 } from "@inrupt/solid-client-authn-browser";
7 import { onMount } from "svelte";
8 import Tasks from "../lib/components/Tasks.svelte";
9 import NewTask from "../lib/components/NewTask.svelte";
10 import { getPodTasks } from "../lib/solid";
11 import tasks from "../lib/store/tasksStore";
12 import podInfo from "../lib/store/podInfoStore";
13 import { getPodUrlAll } from "@inrupt/solid-client";
14
15 let { navigate }: PageProps = $props();
16 let sessionInfo = $state(getDefaultSession()?.info);
17
18 onMount(async () => {
19 const info = await handleIncomingRedirect({
20 restorePreviousSession: true,
21 });
22 if (!info?.isLoggedIn) navigate("/login");
23 else if (!info?.webId)
24 console.error(`Invalid info received from Pod. No WebId found.`);
25 else {
26 sessionInfo = info;
27
28 // Load pod info
29 const pods = await getPodUrlAll(sessionInfo?.webId, { fetch: fetch });
30 const firstPod = pods?.[0];
31 if (firstPod) $podInfo.podUrl = firstPod;
32
33 // Load tasks from pod
34 const podTasks = await getPodTasks(firstPod);
35 tasks.set(podTasks);
36 }
37 });
38</script>
39
40{#if sessionInfo.isLoggedIn}
41 <div>
42 Hey {sessionInfo?.webId} !
43 <Tasks tasks={$tasks} />
44 <NewTask />
45 </div>
46{:else}
47 Authentification...
48{/if}