1
0
Fork 0
mirror of synced 2024-06-02 18:44:54 +12:00

More error handling around config saving

This commit is contained in:
Peter Clement 2021-07-16 14:07:48 +01:00
parent 2afb6ffe2d
commit 3fbd762979
2 changed files with 29 additions and 16 deletions

View file

@ -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)
})
}

View file

@ -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 {