Files
ClaudeMarketing/app/api/settings/test/route.ts
T
Trey T 55fb221faa feat(settings): per-integration Test button with live API checks
Each integration card now has a Test button that re-runs its
connectivity check on demand and updates the badge in place.

- Refactors checkIntegrationStatus into checkIntegration(name) so a
  single integration can be tested without firing the others.
- Adds POST /api/settings/test for the on-demand check.
- Replaces the "key exists ⇒ connected" placeholder for Tavily,
  Gemini, and Nextdoor with real API calls (Tavily search, Gemini
  models list, Nextdoor advertiser fetch). 401/403 surface as
  "Invalid API key" / "Token expired or invalid" so a stale
  credential is obvious instead of pretending to be healthy.
- Fixes Postiz auth header (was Bearer, the rest of the codebase
  passes the API key bare — matches lib/postiz.ts now).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 21:03:16 -05:00

20 lines
699 B
TypeScript

import { auth } from "@/lib/auth";
import { checkIntegration, type IntegrationName } from "@/lib/settings";
const VALID: IntegrationName[] = ["claude", "postiz", "tavily", "gemini", "nextdoor"];
export async function POST(request: Request) {
const session = await auth();
if (!session) return new Response("Unauthorized", { status: 401 });
const body = await request.json().catch(() => ({}));
const name = body?.integration as IntegrationName | undefined;
if (!name || !VALID.includes(name)) {
return Response.json({ error: "integration must be one of: " + VALID.join(", ") }, { status: 400 });
}
const status = await checkIntegration(name);
return Response.json(status);
}