blob: 005eb347d1804761bfa3373b2557034cc3bf5221 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
<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();
}
async function initActual() {
await initActual()
}
</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>
<Button onclick={clearAuth}>Slett autorisasjon</Button>
<Button onclick={refreshAuth}>Oppdater autorisasjon</Button>
<Button></Button>
{/if}
{:else}
<Button onclick={authorize} loading={navigating}>Autentisér hos Sparebanken 1</Button>
{/if}
</main>
<style>
pre {
max-width: 50vw;
overflow: auto;
}
</style>
|