From 3fbd762979277e9fed02c5fd51519c5e6914079d Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 16 Jul 2021 14:07:48 +0100 Subject: [PATCH] More error handling around config saving --- .../builder/portal/manage/auth/index.svelte | 43 ++++++++++++------- .../builder/src/stores/portal/organisation.js | 2 +- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte index 2c5f5c339f..f2c7981a27 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -92,6 +92,15 @@ const providers = { google, oidc } // Create a flag so that it will only try to save completed forms + + $: trySaveGoogle = + providers.google?.config.clientID || + providers.google?.config.clientSecret || + providers.google?.config.callbackURL + $: trySaveOidc = + providers.oidc?.config?.configs[0].configUrl || + providers.oidc?.config?.configs[0].clientID || + providers.oidc?.config?.configs[0].clientSecret $: googleComplete = providers.google?.config.clientID && providers.google?.config.clientSecret && @@ -130,23 +139,27 @@ element.config.configs.forEach(config => { !config.uuid && (config.uuid = uuid()) }) - if (oidcComplete) { - calls.push(api.post(`/api/admin/configs`, element)) - completed.push(ConfigTypes.OIDC) - } else { - notifications.error( - `Please fill in all required ${ConfigTypes.OIDC} fields` - ) + if (trySaveOidc) { + if (!oidcComplete) { + notifications.error( + `Please fill in all required ${ConfigTypes.OIDC} fields` + ) + } else { + calls.push(api.post(`/api/admin/configs`, element)) + completed.push(ConfigTypes.OIDC) + } } } if (element.type === ConfigTypes.Google) { - if (googleComplete) { - calls.push(api.post(`/api/admin/configs`, element)) - completed.push(ConfigTypes.OIDC) - } else { - notifications.error( - `Please fill in all required ${ConfigTypes.Google} fields` - ) + if (trySaveGoogle) { + if (!googleComplete) { + notifications.error( + `Please fill in all required ${ConfigTypes.Google} fields` + ) + } else { + calls.push(api.post(`/api/admin/configs`, element)) + completed.push(ConfigTypes.Google) + } } } }) @@ -167,7 +180,7 @@ notifications.success(`Settings saved.`) }) .catch(err => { - notifications.error(`Failed to update OAuth settings. ${err}`) + notifications.error(`Failed to update auth settings. ${err}`) throw new Error(err.message) }) } diff --git a/packages/builder/src/stores/portal/organisation.js b/packages/builder/src/stores/portal/organisation.js index e7a9c3eea6..71c0be4b4d 100644 --- a/packages/builder/src/stores/portal/organisation.js +++ b/packages/builder/src/stores/portal/organisation.js @@ -17,7 +17,7 @@ export function createOrganisationStore() { async function init() { const res = await api.get(`/api/admin/configs/public`) const json = await res.json() - console.log(json) + if (json.status === 400) { set(DEFAULT_CONFIG) } else {