Add account API key management

This commit is contained in:
Mike Cao committed 2026-09-01 21:50:07 -07:00
1 parent 98b824ce48
commit f1c5b4f7bb
32 files changed
+1618 -15

No files matched your search

@@ -0,0 +1,21 @@
-- CreateTable
CREATE TABLE "api_key" (
"api_key_id" UUID NOT NULL,
"user_id" UUID NOT NULL,
"name" VARCHAR(255) NOT NULL,
"key_hash" VARCHAR(128) NOT NULL,
"key_prefix" VARCHAR(20) NOT NULL,
"last_used_at" TIMESTAMPTZ(6),
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "api_key_pkey" PRIMARY KEY ("api_key_id")
);
-- CreateIndex
CREATE UNIQUE INDEX "api_key_key_hash_key" ON "api_key"("key_hash");
-- CreateIndex
CREATE INDEX "api_key_user_id_idx" ON "api_key"("user_id");
-- AddForeignKey
ALTER TABLE "api_key" ADD CONSTRAINT "api_key_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("user_id") ON DELETE CASCADE ON UPDATE CASCADE;
+16
View File
@@ -32,10 +32,26 @@ model User {
twoFactorBackupCodes TwoFactorBackupCode[]
twoFactorOtpUseds TwoFactorOtpUsed[]
twoFactorRateLimit TwoFactorRateLimit?
apiKeys ApiKey[]
@@map("user")
}
model ApiKey {
id String @id() @map("api_key_id") @db.Uuid
userId String @map("user_id") @db.Uuid
name String @db.VarChar(255)
keyHash String @unique @map("key_hash") @db.VarChar(128)
keyPrefix String @map("key_prefix") @db.VarChar(20)
lastUsedAt DateTime? @map("last_used_at") @db.Timestamptz(6)
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@index([userId])
@@map("api_key")
}
model Session {
id String @id() @map("session_id") @db.Uuid
websiteId String @map("website_id") @db.Uuid