koala73/worldmonitor · warning
Account changed while creating the embed key. Try again.
Error message
Account changed while creating the embed key. Try again.
What it means
After confirming the Convex client exists, createEmbedKey waits for Clerk auth to become available for the captured userId via waitForConvexAuthForUser. If auth never resolves for that user — typically because the signed-in account changed mid-operation — the key is not created and this error tells the user to retry.
Solutions
- Simply retry the operation while staying signed in to the same account.
- Avoid switching or signing out of the Clerk account until the key creation completes.
- Re-check the current user id before the mutation and abort early if it changed.
- If it reproduces without account changes, inspect Clerk token loading/refresh for the user.
Example fix
// before
if (!await waitForConvexAuthForUser(userId)) {
throw new Error('Account changed while creating the embed key. Try again.');
}
// after
const latestUserId = getCurrentClerkUser()?.id;
if (latestUserId !== userId) throw new Error('Account changed while creating the embed key. Try again.');
if (!await waitForConvexAuthForUser(userId)) throw new Error('Sign-in not ready; try again.'); Defensive patterns
Strategy: try-catch
Try / catch
try {
await createEmbedKey(name);
} catch (e) {
if (e.message.startsWith('Account changed')) setStatus('Session changed — please try again.');
else throw e;
} Prevention
- Don't switch or sign out of accounts mid-operation.
- Re-read the current user id immediately before the mutation and compare.
- Keep sessions refreshed so token availability doesn't lag behind the operation.
When it happens
Trigger: User signs out or switches Clerk accounts between the createEmbedKey call capturing userId and the Convex mutation needing an authenticated token for that userId; waitForConvexAuthForUser returns false.
Common situations: User clicking 'create key' in one tab while signing out in another; account switcher used during the operation; slow Clerk token refresh colliding with a sign-out; session expiry racing with the mutation.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- UNAUTHENTICATED
- Authentication unavailable while loading MCP clients. Try ag
- Authentication unavailable while loading Business Pro seats.
- Authentication unavailable while loading embed keys. Try aga
- Account changed while revoking the embed key. Try again.
AI-assisted analysis of koala73/worldmonitor@7d06c8633d (2026-09-15).
Data as JSON: /api/errors/0fa6fbe0fcc892d9.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/embed-keys.ts:92
return plaintext.slice(0, 9);
}
/**
* Create a new embed key for the current user.
* Returns the full plaintext key (shown once) and metadata.
*/
export async function createEmbedKey(name: string): Promise<CreateEmbedKeyResult> {
const userId = getCurrentClerkUser()?.id;
if (!userId) throw new Error('Sign in to create an embed key.');
const plaintext = generateEmbedKey();
const keyPrefix = embedKeyPrefix(plaintext);
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 embed key. Try again.');
}
const result = await settleAccountOperation(
userId,
'creating the embed key',
() => client.mutation(
(api as any).embedKeys.createEmbedKey,
{ name: name.trim(), keyPrefix, keyHash },
),
);
assertAccountStillCurrent(userId, 'creating the embed key');
return { id: result.id, name: result.name, keyPrefix: result.keyPrefix, key: plaintext };
}
/** List all embed keys for the current user. */
export async function listEmbedKeys(): Promise<EmbedKeyInfo[]> {
const userId = getCurrentClerkUser()?.id;View on GitHub (pinned to 7d06c8633d)