koala73/worldmonitor · error · Error
Account changed while creating the API key. Try again.
Error message
Account changed while creating the API key. Try again.
What it means
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.
Source
Thrown at src/services/api-keys.ts:67
return Array.from(new Uint8Array(buf), (b) => b.toString(16).padStart(2, '0')).join('');
}
/**
* Create a new API key for the current user.
* Returns the full plaintext key (shown once) and metadata.
*/
export async function createApiKey(name: string): Promise<CreateApiKeyResult> {
const userId = getCurrentClerkUser()?.id;
if (!userId) throw new Error('Sign in to create an API key.');
const plaintext = generateKey();
const keyPrefix = plaintext.slice(0, 8);
const keyHash = await sha256Hex(plaintext);
const [client, api] = await Promise.all([getConvexClient(), getConvexApi()]);
if (!client || !api) throw new Error('Convex unavailable');
if (!await waitForConvexAuthForUser(userId)) {
throw new Error('Account changed while creating the API key. Try again.');
}
const result = await settleAccountOperation(
userId,
'creating the API key',
() => client.mutation(
(api as any).apiKeys.createApiKey,
{ name: name.trim(), keyPrefix, keyHash },
),
);
assertAccountStillCurrent(userId, 'creating the API key');
return { id: result.id, name: result.name, keyPrefix: result.keyPrefix, key: plaintext };
}
/** List all API keys for the current user. */
export async function listApiKeys(): Promise<ApiKeyInfo[]> {
const userId = getCurrentClerkUser()?.id;View on GitHub (pinned to eeab0a219f)
Solutions
- Retry key creation after the account switch settles
- Avoid switching accounts while an API-key creation is in progress
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at src/services/api-keys.ts:67 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of koala73/worldmonitor@eeab0a219f (2026-08-21).
Data as JSON: /api/errors/fd2fab33a0ece63a.
Report an issue: GitHub.