koala73/worldmonitor · error · Error
Sign in to create an API key.
Error message
Sign in to create an API key.
What it means
UI service error in createApiKey: no Clerk user is currently authenticated (getCurrentClerkUser returned null). API keys are per-user, so key creation is impossible without a session. It is a precondition guard, not a server failure.
Source
Thrown at src/services/api-keys.ts:58
const raw = new Uint8Array(20);
crypto.getRandomValues(raw);
const hex = Array.from(raw, (b) => b.toString(16).padStart(2, '0')).join('');
return `wm_${hex}`;
}
/** SHA-256 hex digest of a string. */
async function sha256Hex(input: string): Promise<string> {
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(input));
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 },
),View on GitHub (pinned to eeab0a219f)
Solutions
- Sign in and wait for the Clerk session to fully load before retrying
- If already signed in, the session may still be initializing — retry after auth state settles
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at src/services/api-keys.ts:58 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/2ce0227288d3b84b.
Report an issue: GitHub.