feat: API Keys via Umgebungsvariablen konfigurierbar

- Neuer getApiKey() Helper: prüft zuerst ENV-Vars, dann DB
- Alle Job-Routes nutzen getApiKey() statt direktem DB-Lookup
- Credentials-Status berücksichtigt ENV-Vars (Sidebar-Haken)
- .env.local.example: Platzhalter für alle 4 API Keys

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Timo Uttenweiler
2026-03-20 13:58:41 +01:00
parent 39760b20a9
commit ea93d674a2
9 changed files with 54 additions and 49 deletions

23
lib/utils/apiKey.ts Normal file
View File

@@ -0,0 +1,23 @@
import { prisma } from "@/lib/db";
import { decrypt } from "./encryption";
const ENV_VARS: Record<string, string> = {
anymailfinder: "ANYMAILFINDER_API_KEY",
apify: "APIFY_API_KEY",
vayne: "VAYNE_API_KEY",
googlemaps: "GOOGLE_MAPS_API_KEY",
};
export async function getApiKey(service: string): Promise<string | null> {
const envVar = ENV_VARS[service];
if (envVar && process.env[envVar]) return process.env[envVar]!;
const cred = await prisma.apiCredential.findUnique({ where: { service } });
if (!cred?.value) return null;
return decrypt(cred.value);
}
export function hasApiKeyFromEnv(service: string): boolean {
const envVar = ENV_VARS[service];
return !!(envVar && process.env[envVar]);
}