{"record":{"id":"ccd38b206392a237","repo":"windmill-labs/windmill","slug":"could-not-determine-current-admin-email","errorCode":null,"errorMessage":"Could not determine current admin email","messagePattern":"Could not determine current admin email","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/src/routes/(root)/(logged)/user/(user)/instance_settings/+page.svelte","lineNumber":289,"sourceCode":"\t\tyamlMode = false\n\t\tfullStep = 0\n\t\tmode = 'wizard'\n\t}\n\n\tfunction finishSetup() {\n\t\tgoto('/user/workspaces')\n\t}\n\n\tasync function submitAccount() {\n\t\taccountError = ''\n\t\taccountSubmitting = true\n\t\ttry {\n\t\t\tlet oldEmail = $superadmin\n\t\t\tif (!oldEmail) {\n\t\t\t\toldEmail = await UserService.getCurrentEmail()\n\t\t\t}\n\t\t\tif (!oldEmail) {\n\t\t\t\tthrow new Error('Could not determine current admin email')\n\t\t\t}\n\n\t\t\tawait UserService.createUserGlobally({\n\t\t\t\trequestBody: {\n\t\t\t\t\temail: newEmail,\n\t\t\t\t\tpassword: newPassword,\n\t\t\t\t\tsuper_admin: true\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst token = await UserService.login({\n\t\t\t\trequestBody: { email: newEmail, password: newPassword }\n\t\t\t})\n\n\t\t\t// Update the client token for subsequent requests\n\t\t\tconst { OpenAPI } = await import('$lib/gen')\n\t\t\tOpenAPI.TOKEN = token\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/frontend/src/routes/(root)/(logged)/user/(user)/instance_settings/+page.svelte#L271-L307","documentation":"In submitAccount on the instance settings page, changing the superadmin's email is implemented as creating the new admin user then removing the old one, which requires knowing the current admin email. If neither the $superadmin store nor UserService.getCurrentEmail() yields a value, the page throws this error rather than proceeding and potentially locking out the admin.","triggerScenarios":"Submitting the account-change form when the $superadmin store is empty AND UserService.getCurrentEmail() returns null/empty — e.g. the session user isn't resolvable as the current admin, or the API call failed silently.","commonSituations":"Calling the flow from a non-superadmin context; backend returning an empty current-email (auth token expired between page load and submit); a stale/blank superadmin store after instance config changed.","solutions":["Refresh the page and log in again as the superadmin so getCurrentEmail() resolves","Verify the session token is valid and not expired before submitting","Check GET current-email endpoint works in the network tab; investigate backend if it returns empty","Set the new email via CLI/DB directly if the UI flow stays blocked"],"exampleFix":"// before\nlet oldEmail = $superadmin\nif (!oldEmail) oldEmail = await UserService.getCurrentEmail()\n// after\nlet oldEmail = $superadmin\nif (!oldEmail) {\n  oldEmail = await UserService.getCurrentEmail()\n  if (!oldEmail) throw new Error('Could not determine current admin email — re-login as superadmin and retry')\n}","handlingStrategy":"try-catch","validationCode":"let oldEmail = $superadmin ?? (await UserService.getCurrentEmail())\nif (!oldEmail) {\n  sendUserToast('Re-login as superadmin before changing the admin account', true)\n  return\n}","typeGuard":"function isNonEmptyString(v: unknown): v is string { return typeof v === 'string' && v.length > 0 }","tryCatchPattern":"try {\n  await submitAccount()\n} catch (e) {\n  if (e.message === 'Could not determine current admin email') {\n    await refreshSession() // re-auth then retry once\n    await submitAccount()\n  } else throw e\n}","preventionTips":["Hydrate the $superadmin store on page load before enabling the account form","Handle 401 from getCurrentEmail() by redirecting to login instead of storing empty","Avoid long idle periods between loading settings and submitting (token expiry)","Keep a CLI/superadmin recovery path for account changes"],"tags":["auth","admin","frontend","state"],"backgroundTag":"missing-current-user-email","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}