From bfa810fbb25b17ac50dfe3becfd32cd23ea8995b Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 15 Mar 2023 23:28:57 +0100 Subject: [PATCH] feat(frontend): list tokens, use formatted dates --- frontend/package.json | 1 + frontend/pnpm-lock.yaml | 6 +++ frontend/src/lib/api/entities.ts | 2 +- .../routes/auth/login/discord/+page.server.ts | 2 +- frontend/src/routes/settings/+layout.svelte | 2 +- frontend/src/routes/settings/+page.svelte | 11 +----- frontend/src/routes/settings/export/+page.ts | 2 +- .../src/routes/settings/invites/+page.svelte | 9 ++++- .../src/routes/settings/tokens/+page.svelte | 37 ++++++++++++++++++- frontend/src/routes/settings/tokens/+page.ts | 12 ++++++ 10 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 frontend/src/routes/settings/tokens/+page.ts diff --git a/frontend/package.json b/frontend/package.json index fd766a9..99d7ef9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -43,6 +43,7 @@ "base64-arraybuffer": "^1.0.2", "bootstrap": "5.3.0-alpha1", "bootstrap-icons": "^1.10.3", + "jose": "^4.13.1", "luxon": "^3.3.0", "marked": "^4.2.12", "sanitize-html": "^2.10.0", diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 9b5901d..37f87c7 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -20,6 +20,7 @@ specifiers: eslint: ^8.28.0 eslint-config-prettier: ^8.5.0 eslint-plugin-svelte3: ^4.0.0 + jose: ^4.13.1 luxon: ^3.3.0 marked: ^4.2.12 postcss: ^8.4.21 @@ -40,6 +41,7 @@ dependencies: base64-arraybuffer: 1.0.2 bootstrap: 5.3.0-alpha1_@popperjs+core@2.11.6 bootstrap-icons: 1.10.3 + jose: 4.13.1 luxon: 3.3.0 marked: 4.2.12 sanitize-html: 2.10.0 @@ -1546,6 +1548,10 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true + /jose/4.13.1: + resolution: {integrity: sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ==} + dev: false + /js-sdsl/4.3.0: resolution: {integrity: sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==} dev: true diff --git a/frontend/src/lib/api/entities.ts b/frontend/src/lib/api/entities.ts index 0f7ad2d..470bc65 100644 --- a/frontend/src/lib/api/entities.ts +++ b/frontend/src/lib/api/entities.ts @@ -74,7 +74,7 @@ export interface MemberPartialUser { export interface Invite { code: string; - created: Date; + created: string; used: boolean; } diff --git a/frontend/src/routes/auth/login/discord/+page.server.ts b/frontend/src/routes/auth/login/discord/+page.server.ts index ec5828f..eb851da 100644 --- a/frontend/src/routes/auth/login/discord/+page.server.ts +++ b/frontend/src/routes/auth/login/discord/+page.server.ts @@ -32,5 +32,5 @@ interface CallbackResponse { require_invite: boolean; is_deleted: boolean; - deleted_at?: Date; + deleted_at?: string; } diff --git a/frontend/src/routes/settings/+layout.svelte b/frontend/src/routes/settings/+layout.svelte index 3a4fc54..005502f 100644 --- a/frontend/src/routes/settings/+layout.svelte +++ b/frontend/src/routes/settings/+layout.svelte @@ -46,7 +46,7 @@ active={$page.url.pathname === "/settings/tokens"} href="/settings/tokens" > - API tokens + Tokens { interface ExportResponse { path: string; - created_at: Date; + created_at: string; } diff --git a/frontend/src/routes/settings/invites/+page.svelte b/frontend/src/routes/settings/invites/+page.svelte index 9849972..a126da4 100644 --- a/frontend/src/routes/settings/invites/+page.svelte +++ b/frontend/src/routes/settings/invites/+page.svelte @@ -2,7 +2,8 @@ import type { APIError, Invite } from "$lib/api/entities"; import { apiFetchClient } from "$lib/api/fetch"; import ErrorAlert from "$lib/components/ErrorAlert.svelte"; - import { Alert, Button, Modal, Table } from "sveltestrap"; + import { DateTime } from "luxon"; + import { Button, Modal, Table } from "sveltestrap"; import type { PageData } from "./$types"; export let data: PageData; @@ -43,7 +44,11 @@ {#each data.invites as invite} {invite.code} - {invite.created} + {DateTime.fromISO(invite.created) + .toLocal() + .toLocaleString(DateTime.DATETIME_MED)} {invite.used ? "yes" : "no"} {/each} diff --git a/frontend/src/routes/settings/tokens/+page.svelte b/frontend/src/routes/settings/tokens/+page.svelte index c337520..fc2a0fd 100644 --- a/frontend/src/routes/settings/tokens/+page.svelte +++ b/frontend/src/routes/settings/tokens/+page.svelte @@ -1,3 +1,36 @@ -

API tokens

+ + +

Tokens ({data.tokens.length})

+ + + + + + + + + + {#each data.tokens as token} + + + + + + + {/each} + +
IDCreated atExpires atCurrent?
{token.id}{DateTime.fromISO(token.created).toLocal().toLocaleString(DateTime.DATETIME_MED)}{DateTime.fromISO(token.expires).toLocal().toLocaleString(DateTime.DATETIME_MED)}{#if claims["jti"] === token.id}{:else}{/if}
diff --git a/frontend/src/routes/settings/tokens/+page.ts b/frontend/src/routes/settings/tokens/+page.ts new file mode 100644 index 0000000..6ad1310 --- /dev/null +++ b/frontend/src/routes/settings/tokens/+page.ts @@ -0,0 +1,12 @@ +import { apiFetchClient } from "$lib/api/fetch"; + +export const load = async () => { + const tokens = await apiFetchClient("/auth/tokens"); + return { tokens }; +}; + +interface Token { + id: string; + created: string; + expires: string; +}