rotateApiKey()
Rotates an existing key using the app-scoped route and returns a new one-time secret.
Usage
The following example shows a basic usage of the backend client from @wacht/nextjs/server.
import { wachtClient } from '@wacht/nextjs/server';export async function rotateKey(appName: string, keyId: string) { const client = await wachtClient(); return client.apiKeys.rotateApiKey(appName, keyId);}Signature
function rotateApiKey( appName: string, keyId: string,): Promise<ApiKeyWithSecret>Parameters
›appName?: string | undefined;
appName?: string | undefined;Slug of the app that owns the key.
›keyId?: string | undefined;
keyId?: string | undefined;Identifier of the key to rotate.
Return value
›key?: ApiKey | undefined;
key?: ApiKey | undefined;Updated key record after rotation.
›id?: string | undefined;
id?: string | undefined;Stable key id.
›app_slug?: string | undefined;
app_slug?: string | undefined;Owning app slug.
›name?: string | undefined;
name?: string | undefined;Key display name.
›key_prefix?: string | undefined;
key_prefix?: string | undefined;Public key prefix.
›key_suffix?: string | undefined;
key_suffix?: string | undefined;Public key suffix.
›permissions?: string[] | undefined;
permissions?: string[] | undefined;Permissions attached to the key.
›secret?: string | undefined;
secret?: string | undefined;New secret value returned once.
Behavior
- Wraps the corresponding backend endpoint for this capability.
- Use the returned payload as canonical backend state for follow-up operations.
Examples
Rotate a compromised key
import { wachtClient } from '@wacht/nextjs/server';export async function rotateCompromisedKey() { const client = await wachtClient(); return client.apiKeys.rotateApiKey('internal-api', '12345');}