feat: add MCP endpoint and API key management
- Add ApiKey Prisma model (SHA-256 hash, prefix, lastUsedAt) with migration - Implement ApiKeyService (create, list, delete, verify) - Extend requireAuth middleware to accept sk_-prefixed API keys alongside JWTs - Add GET/POST /api-keys routes for creating and revoking keys - Add stateless Streamable HTTP MCP server at POST/GET /mcp exposing all 20 time-tracking tools (clients, projects, time entries, timer, statistics, client targets and corrections) - Frontend: ApiKey types, apiKeys API module, useApiKeys hook - Frontend: ApiKeysPage with key table, one-time raw-key reveal modal, and inline revoke confirmation - Wire /api-keys route and add API Keys link to Management dropdown in Navbar
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "client_targets" ALTER COLUMN "working_days" DROP DEFAULT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "api_keys" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"key_hash" VARCHAR(64) NOT NULL,
|
||||
"prefix" VARCHAR(16) NOT NULL,
|
||||
"last_used_at" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"user_id" VARCHAR(255) NOT NULL,
|
||||
|
||||
CONSTRAINT "api_keys_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "api_keys_key_hash_key" ON "api_keys"("key_hash");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "api_keys_user_id_idx" ON "api_keys"("user_id");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -20,6 +20,7 @@ model User {
|
||||
timeEntries TimeEntry[]
|
||||
ongoingTimer OngoingTimer?
|
||||
clientTargets ClientTarget[]
|
||||
apiKeys ApiKey[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -151,3 +152,18 @@ model Session {
|
||||
|
||||
@@map("sessions")
|
||||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @default(uuid())
|
||||
name String @db.VarChar(255)
|
||||
keyHash String @unique @map("key_hash") @db.VarChar(64) // SHA-256 hex
|
||||
prefix String @db.VarChar(16) // first chars of raw key for display
|
||||
lastUsedAt DateTime? @map("last_used_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
userId String @map("user_id") @db.VarChar(255)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
@@map("api_keys")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user