From 57861411f37a07af3cd8fcf1520843e5a5e44bfc Mon Sep 17 00:00:00 2001
From: ivar <i@oiee.no>
Date: Wed, 10 Dec 2025 00:17:27 +0100
Subject: Initial commit

---
 app/src/routes/+page.svelte | 64 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 app/src/routes/+page.svelte

(limited to 'app/src/routes/+page.svelte')

diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte
new file mode 100644
index 0000000..ed35a84
--- /dev/null
+++ b/app/src/routes/+page.svelte
@@ -0,0 +1,64 @@
+<script lang="ts">
+    import Button from "$lib/ui/button.svelte";
+    import {
+        clearTokens,
+        createSb1SyncSessionAndReturnLoginUrl,
+        getAccounts,
+        getTokenExpires,
+        getTransactions,
+        refreshSB1Token,
+    } from "./sb1.remote";
+
+    let navigating = $state(false);
+
+    async function authorize() {
+        navigating = true;
+        const url = await createSb1SyncSessionAndReturnLoginUrl();
+        location.href = url;
+        navigating = false;
+    }
+
+    async function clearAuth() {
+        await clearTokens();
+        getTokenExpires().refresh();
+    }
+
+    async function refreshAuth() {
+        await refreshSB1Token();
+        getTokenExpires().refresh();
+    }
+</script>
+
+<main>
+    {#if await getTokenExpires()}
+        {@const tokens = await getTokenExpires()}
+        {@const accounts = await getAccounts()}
+        {#if tokens}
+            <pre>accessToken: {tokens.accessToken.created.add({ seconds: tokens.accessToken.expires }).toLocaleString()}
+refreshToken: {tokens.refreshToken.created.add({ seconds: tokens.refreshToken.expires }).toLocaleString()}</pre>
+            <ul>
+                {#each accounts.accounts as account}
+                    {@const transactions = await getTransactions(account.key)}
+                    <li>{account.name}</li>
+                    <ul>
+                        {#each transactions?.transactions as transaction}
+                            <li>{JSON.stringify(transaction)}</li>
+                        {/each}
+                    </ul>
+                {/each}
+            </ul>
+        {:else}
+            <Button onclick={clearAuth}>Slett autorisasjon</Button>
+            <Button onclick={refreshAuth}>Oppdater autorisasjon</Button>
+        {/if}
+    {:else}
+        <Button onclick={authorize} loading={navigating}>Autentisér hos Sparebanken 1</Button>
+    {/if}
+</main>
+
+<style>
+    pre {
+        max-width: 50vw;
+        overflow: auto;
+    }
+</style>
-- 
cgit v1.3

