From 4086c8f439e73515d6c5ee22035e4667ed738cec Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 28 Feb 2022 18:39:05 +0000 Subject: [PATCH] Fixes for review comments. --- .../settings/UpdateAPIKeyModal.svelte | 8 +++-- .../src/pages/builder/portal/_layout.svelte | 2 +- packages/builder/src/stores/portal/auth.js | 5 ++- packages/frontend-core/src/api/self.js | 36 +++++++++++++++++-- packages/frontend-core/src/api/user.js | 31 ---------------- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/packages/builder/src/components/settings/UpdateAPIKeyModal.svelte b/packages/builder/src/components/settings/UpdateAPIKeyModal.svelte index c82be19fed..4322822ec8 100644 --- a/packages/builder/src/components/settings/UpdateAPIKeyModal.svelte +++ b/packages/builder/src/components/settings/UpdateAPIKeyModal.svelte @@ -9,7 +9,7 @@ async function generateAPIKey() { try { apiKey = await auth.generateAPIKey() - notifications.success("New API key generated.") + notifications.success("New API key generated") } catch (err) { notifications.error("Unable to generate new API key") } @@ -18,7 +18,11 @@ } onMount(async () => { - apiKey = await auth.fetchAPIKey() + try { + apiKey = await auth.fetchAPIKey() + } catch (err) { + notifications.error("Unable to fetch API key") + } }) diff --git a/packages/builder/src/pages/builder/portal/_layout.svelte b/packages/builder/src/pages/builder/portal/_layout.svelte index 876f34c0bb..7aa4671f7c 100644 --- a/packages/builder/src/pages/builder/portal/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/_layout.svelte @@ -166,7 +166,7 @@ {#if $auth.isBuilder} apiKeyModal.show()}> - View developer information + View API key {/if} { - const info = await API.generateAPIKey() - return info?.apiKey ? info.apiKey : null + return API.generateAPIKey() }, fetchAPIKey: async () => { const info = await API.fetchDeveloperInfo() - return info?.apiKey ? info.apiKey : null + return info?.apiKey }, } diff --git a/packages/frontend-core/src/api/self.js b/packages/frontend-core/src/api/self.js index f4d2c1c313..cdd5eaba53 100644 --- a/packages/frontend-core/src/api/self.js +++ b/packages/frontend-core/src/api/self.js @@ -5,9 +5,10 @@ export const buildSelfEndpoints = API => ({ * @return {Promise} returns the API response, including an API key. */ generateAPIKey: async () => { - return await API.post({ + const response = await API.post({ url: "/api/global/self/api_key", }) + return response?.apiKey }, /** @@ -15,8 +16,39 @@ export const buildSelfEndpoints = API => ({ * @return {Promise} An object containing the user developer information. */ fetchDeveloperInfo: async () => { - return await API.get({ + return API.get({ url: "/api/global/self/api_key", }) }, + + /** + * Fetches the currently logged-in user object. + * Used in client apps. + */ + fetchSelf: async () => { + return await API.get({ + url: "/api/self", + }) + }, + + /** + * Fetches the currently logged-in user object. + * Used in the builder. + */ + fetchBuilderSelf: async () => { + return await API.get({ + url: "/api/global/self", + }) + }, + + /** + * Updates the current logged-in user. + * @param user the new user object to save + */ + updateSelf: async user => { + return await API.post({ + url: "/api/global/self", + body: user, + }) + }, }) diff --git a/packages/frontend-core/src/api/user.js b/packages/frontend-core/src/api/user.js index 7c715e9b63..9eade435da 100644 --- a/packages/frontend-core/src/api/user.js +++ b/packages/frontend-core/src/api/user.js @@ -1,24 +1,4 @@ export const buildUserEndpoints = API => ({ - /** - * Fetches the currently logged-in user object. - * Used in client apps. - */ - fetchSelf: async () => { - return await API.get({ - url: "/api/self", - }) - }, - - /** - * Fetches the currently logged-in user object. - * Used in the builder. - */ - fetchBuilderSelf: async () => { - return await API.get({ - url: "/api/global/self", - }) - }, - /** * Gets a list of users in the current tenant. */ @@ -61,17 +41,6 @@ export const buildUserEndpoints = API => ({ }) }, - /** - * Updates the current logged-in user. - * @param user the new user object to save - */ - updateSelf: async user => { - return await API.post({ - url: "/api/global/self", - body: user, - }) - }, - /** * Creates or updates a user in the current tenant. * @param user the new user to create