diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index bd57eec08..ada7e1ff8 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -62,7 +62,7 @@ import { usePaste } from '@/composables/usePaste' import { useWorkflowPersistence } from '@/composables/useWorkflowPersistence' import { CORE_SETTINGS } from '@/constants/coreSettings' import { i18n } from '@/i18n' -import { api } from '@/scripts/api' +import { UnauthorizedError, api } from '@/scripts/api' import { app as comfyApp } from '@/scripts/app' import { ChangeTracker } from '@/scripts/changeTracker' import { IS_CONTROL_WIDGET, updateControlWidgetLabel } from '@/scripts/widgets' @@ -241,7 +241,20 @@ onMounted(async () => { // some listeners of litegraph canvas. ChangeTracker.init(comfyApp) await loadCustomNodesI18n() - await settingStore.loadSettingValues() + try { + await settingStore.loadSettingValues() + } catch (error) { + if (error instanceof UnauthorizedError) { + console.log( + 'Failed loading user settings, user unauthorized, cleaning local Comfy.userId' + ) + localStorage.removeItem('Comfy.userId') + localStorage.removeItem('Comfy.userName') + window.location.reload() + } else { + throw error + } + } CORE_SETTINGS.forEach((setting) => { settingStore.addSetting(setting) }) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index c18d9b04a..9ebde1ad6 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -79,6 +79,8 @@ interface ApiMessage { data: ApiCalls[T] } +export class UnauthorizedError extends Error {} + /** Ensures workers get a fair shake. */ type Unionize = T[keyof T] @@ -732,7 +734,12 @@ export class ComfyApi extends EventTarget { * @returns { Promise } A dictionary of id -> value */ async getSettings(): Promise { - return (await this.fetchApi('/settings')).json() + const resp = await this.fetchApi('/settings') + + if (resp.status == 401) { + throw new UnauthorizedError(resp.statusText) + } + return await resp.json() } /**