{"record":{"id":"fd2fab33a0ece63a","repo":"koala73/worldmonitor","slug":"account-changed-while-creating-the-api-key-try-ag","errorCode":null,"errorMessage":"Account changed while creating the API key. Try again.","messagePattern":"Account changed while creating the API key\\. Try again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/api-keys.ts","lineNumber":67,"sourceCode":"  return Array.from(new Uint8Array(buf), (b) => b.toString(16).padStart(2, '0')).join('');\n}\n\n/**\n * Create a new API key for the current user.\n * Returns the full plaintext key (shown once) and metadata.\n */\nexport async function createApiKey(name: string): Promise<CreateApiKeyResult> {\n  const userId = getCurrentClerkUser()?.id;\n  if (!userId) throw new Error('Sign in to create an API key.');\n\n  const plaintext = generateKey();\n  const keyPrefix = plaintext.slice(0, 8);\n  const keyHash = await sha256Hex(plaintext);\n\n  const [client, api] = await Promise.all([getConvexClient(), getConvexApi()]);\n  if (!client || !api) throw new Error('Convex unavailable');\n  if (!await waitForConvexAuthForUser(userId)) {\n    throw new Error('Account changed while creating the API key. Try again.');\n  }\n\n  const result = await settleAccountOperation(\n    userId,\n    'creating the API key',\n    () => client.mutation(\n      (api as any).apiKeys.createApiKey,\n      { name: name.trim(), keyPrefix, keyHash },\n    ),\n  );\n  assertAccountStillCurrent(userId, 'creating the API key');\n\n  return { id: result.id, name: result.name, keyPrefix: result.keyPrefix, key: plaintext };\n}\n\n/** List all API keys for the current user. */\nexport async function listApiKeys(): Promise<ApiKeyInfo[]> {\n  const userId = getCurrentClerkUser()?.id;","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/src/services/api-keys.ts#L49-L85","documentation":"UI service error in createApiKey (via assertAccountStillCurrent): the Clerk-authenticated user changed between the start of key creation and completion — e.g. the user signed out or switched accounts mid-flight. The operation is aborted to avoid attaching the key to the wrong account.","triggerScenarios":"Thrown at src/services/api-keys.ts:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry key creation after the account switch settles","Avoid switching accounts while an API-key creation is in progress"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}