diff --git a/nextjs/.env.example b/nextjs/.env.example index 4b9fc86..733a4ed 100644 --- a/nextjs/.env.example +++ b/nextjs/.env.example @@ -1,3 +1,6 @@ # Set in your Vercel project environment variables. # For local dev: add to .env.local (never commit this file) +# +# The app reads KAK_API_KEY or KAKUNIN_API_KEY. The Vercel Marketplace +# integration injects KAK_API_KEY automatically; for local dev set either. KAKUNIN_API_KEY=kak_live_... diff --git a/nextjs/README.md b/nextjs/README.md index baceff1..757b28a 100644 --- a/nextjs/README.md +++ b/nextjs/README.md @@ -4,7 +4,7 @@ Full-stack example: agent registration, certificate issuance, and middleware-lev ## What this covers -- `lib/kakunin.ts` — singleton SDK init (reads `KAK_API_KEY` from env) +- `lib/kakunin.ts` — singleton SDK init (reads `KAK_API_KEY` or `KAKUNIN_API_KEY` from env) - `app/api/v1/agents/route.ts` — register + certify an agent via POST - `middleware.ts` — enforce cert serial on all `/api/agent/*` routes diff --git a/nextjs/lib/kakunin.ts b/nextjs/lib/kakunin.ts index d16e8e4..bef15e6 100644 --- a/nextjs/lib/kakunin.ts +++ b/nextjs/lib/kakunin.ts @@ -1,8 +1,16 @@ import Kakunin from '@kakunin/sdk'; // Singleton — reuse across requests in the same serverless function instance. -// KAKUNIN_API_KEY is set in your Vercel project environment variables. -// Use kak_live_... for production, kak_test_... for sandbox. -export const kkn = new Kakunin({ - apiKey: process.env.KAKUNIN_API_KEY!, -}); +// The API key comes from your environment. The Vercel Marketplace integration +// injects KAK_API_KEY; local dev / the Deploy button use KAKUNIN_API_KEY. We +// accept either so both paths work. Use kak_live_... for production, +// kak_test_... for sandbox. +const apiKey = process.env.KAK_API_KEY ?? process.env.KAKUNIN_API_KEY; +if (!apiKey) { + throw new Error( + 'Missing Kakunin API key. Set KAKUNIN_API_KEY (or KAK_API_KEY via the ' + + 'Vercel Marketplace integration). Get one at https://kakunin.ai/dashboard/api-keys', + ); +} + +export const kkn = new Kakunin({ apiKey });