From 294d0cc04b8532ba78898466366d7b5cb23f342b Mon Sep 17 00:00:00 2001 From: juansensio Date: Fri, 9 Aug 2024 11:52:00 +0200 Subject: [PATCH] update profile, add api keys management --- ui/src/components/Map.svelte | 2 - ui/src/lib/apikeys/deleteApiKey.js | 4 +- ui/src/lib/apikeys/requestApiKey.js | 2 +- ui/src/lib/apikeys/retrieveApiKey.js | 6 +- .../{+page.server.js => +layout.server.js} | 0 ui/src/routes/profile/+layout.svelte | 12 ++ ui/src/routes/profile/+page.svelte | 40 ++--- ui/src/routes/profile/Credentials.svelte | 1 - ui/src/routes/profile/ProfileNavBar.svelte | 24 +-- ui/src/routes/profile/apikeys/+page.svelte | 148 +++++++++--------- .../profile/credentials/+page.server.js | 17 -- .../routes/profile/credentials/+page.svelte | 18 +-- 12 files changed, 129 insertions(+), 145 deletions(-) rename ui/src/routes/profile/{+page.server.js => +layout.server.js} (100%) create mode 100644 ui/src/routes/profile/+layout.svelte delete mode 100644 ui/src/routes/profile/credentials/+page.server.js diff --git a/ui/src/components/Map.svelte b/ui/src/components/Map.svelte index 01a381b5..eed0188b 100644 --- a/ui/src/components/Map.svelte +++ b/ui/src/components/Map.svelte @@ -6,8 +6,6 @@ export let geojson; - $: console.log(geojson); - let map = null; let zoomPosition = "bottomright"; let options = { diff --git a/ui/src/lib/apikeys/deleteApiKey.js b/ui/src/lib/apikeys/deleteApiKey.js index 61d04b1e..5084f86d 100644 --- a/ui/src/lib/apikeys/deleteApiKey.js +++ b/ui/src/lib/apikeys/deleteApiKey.js @@ -3,8 +3,8 @@ import fetchEOTDL from '$lib/shared/fetchEOTDL'; export default async (token,keyId) => { let url = `${PUBLIC_EOTDL_API}/auth/keys/${keyId}`; - const {data, error} = await fetchEOTDL(url,token, "DELETE"); + const {data, error} = await fetchEOTDL(url, token, "DELETE"); if (error) throw new Error(error); - return data; + return data; }; diff --git a/ui/src/lib/apikeys/requestApiKey.js b/ui/src/lib/apikeys/requestApiKey.js index e4200eb8..35570656 100644 --- a/ui/src/lib/apikeys/requestApiKey.js +++ b/ui/src/lib/apikeys/requestApiKey.js @@ -3,7 +3,7 @@ import fetchEOTDL from '$lib/shared/fetchEOTDL'; export default async (token) => { let url = `${PUBLIC_EOTDL_API}/auth/keys`; - const {data, error} = await fetchEOTDL(url,token, "POST"); + const {data, error} = await fetchEOTDL(url, token, "POST"); if (error) throw new Error(error); return data; }; diff --git a/ui/src/lib/apikeys/retrieveApiKey.js b/ui/src/lib/apikeys/retrieveApiKey.js index 355324aa..6312551d 100644 --- a/ui/src/lib/apikeys/retrieveApiKey.js +++ b/ui/src/lib/apikeys/retrieveApiKey.js @@ -2,9 +2,9 @@ import { PUBLIC_EOTDL_API } from '$env/static/public'; import fetchEOTDL from '$lib/shared/fetchEOTDL'; export default async (token) => { - let url = `${PUBLIC_EOTDL_API}/auth/keys`; - const {data, error} = await fetchEOTDL(url,token, "GET"); + let url = `${PUBLIC_EOTDL_API}/auth/keys`; + const {data, error} = await fetchEOTDL(url, token, "GET"); if (error) throw new Error(error); - return data; + return data; }; diff --git a/ui/src/routes/profile/+page.server.js b/ui/src/routes/profile/+layout.server.js similarity index 100% rename from ui/src/routes/profile/+page.server.js rename to ui/src/routes/profile/+layout.server.js diff --git a/ui/src/routes/profile/+layout.svelte b/ui/src/routes/profile/+layout.svelte new file mode 100644 index 00000000..ade7479b --- /dev/null +++ b/ui/src/routes/profile/+layout.svelte @@ -0,0 +1,12 @@ + + +
+
+ + +
+
diff --git a/ui/src/routes/profile/+page.svelte b/ui/src/routes/profile/+page.svelte index 6b6a429b..7b021eff 100755 --- a/ui/src/routes/profile/+page.svelte +++ b/ui/src/routes/profile/+page.svelte @@ -1,7 +1,6 @@ -

Your credentials:

{#if credentials} - - - +
+

Api Keys

+ + {#each apikeys as key} +
+
+
+

+ Key: + {key.id.slice(1, 8).concat("...")} +

+
+

+ Created on {formatTime(key.createdAt)} +

+
+
+ + +
+
+ {/each}
-
-
- -
-

Api Keys

- -

API key limit reached. Delete an existing key to create a new one.

- {#each apikeys as key} -
-
-
-

Key: {key.id.slice(1,8).concat(" . . .")}

-
-

Created on {formatTime(key.createdAt)}

-
-
- - -
-
- {/each} + + \ No newline at end of file +
+
diff --git a/ui/src/routes/profile/credentials/+page.server.js b/ui/src/routes/profile/credentials/+page.server.js deleted file mode 100644 index 7555ac72..00000000 --- a/ui/src/routes/profile/credentials/+page.server.js +++ /dev/null @@ -1,17 +0,0 @@ -import { redirect } from '@sveltejs/kit'; -import retrieveUserData from '$lib/auth/retrieveUserData'; -import retrieveUserCredentials from '$lib/auth/retrieveUserCredentials'; - -export async function load({ locals, fetch }) { - if (!locals?.user) - throw redirect(307, '/api/auth/login'); - const userData = await retrieveUserData(locals.id_token, fetch) - const credentials = await retrieveUserCredentials(locals.id_token, fetch) - userData.credentials = credentials - return { - id_token: locals.id_token, - user: userData - } -} - -export const prerender = false; \ No newline at end of file diff --git a/ui/src/routes/profile/credentials/+page.svelte b/ui/src/routes/profile/credentials/+page.svelte index 2c523c9d..9e5f6c4e 100644 --- a/ui/src/routes/profile/credentials/+page.svelte +++ b/ui/src/routes/profile/credentials/+page.svelte @@ -1,16 +1,10 @@ -
-
- -
-

Credentials

- -
-
-
\ No newline at end of file +
+

Credentials

+ +