Backend SDK for Wacht APIs, server authentication, gateway authorization, and webhook verification.
Documentation | npm | GitHub
@wacht/backend includes both:
- An API client for Wacht backend resources
- Server-side auth primitives for session/API-key/OAuth token verification
It is designed to run in server runtimes with fetch support.
pnpm add @wacht/backendCreate explicit client instances:
import { WachtClient } from "@wacht/backend";
const client = new WachtClient({
apiKey: process.env.WACHT_API_KEY!,
});
const users = await client.users.listUsers({ limit: 10, offset: 0 });Or use a named client store:
import { createClientStore, WachtClient } from "@wacht/backend";
const store = createClientStore();
new WachtClient({
name: "primary",
apiKey: process.env.WACHT_API_KEY!,
store,
});
const client = store.get("primary");authenticateRequestgetAuthrequireAuthgetAuthFromTokenrequireAuthFromTokenverifyAuthToken
parseFrontendApiUrlFromPublishableKey is available to derive the frontend API URL from a publishable key when needed.
import { gateway } from "@wacht/backend";
const result = await gateway.checkPrincipalAuthz({
principalType: "api_key",
principalValue: "wk_live_xxx",
method: "GET",
resource: "/v1/private",
});import { verifyWebhookSignature } from "@wacht/backend";
const event = verifyWebhookSignature(rawBody, headers, webhookSecret);pnpm build
pnpm test
pnpm lintApache License 2.0. See LICENSE.md.