mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
d6eca611fc
Introduce full API token support: add a Prisma migration to create api_tokens table and indexes; add types, constants and a generateApiToken utility (hashed token + prefix). Update admin and user token routes to use the generator, enforce per-user active token caps, and integrate rate-limit checks. Add an interactive API docs page with TokenInput, EndpointCard and ResponseViewer components, plus a protected page route. Improve confirmation UX with an accessible ConfirmDialog (focus trap, Escape to close, animations) and wire confirm flows into admin/profile token sections; also update ConfirmModal to accept node messages. Add dialog CSS animations and enhance clipboard error handling. Update related middleware, utils and tests to reflect changes.
34 lines
1.1 KiB
SQL
34 lines
1.1 KiB
SQL
-- CreateTable
|
|
CREATE TABLE "api_tokens" (
|
|
"id" TEXT NOT NULL,
|
|
"name" TEXT NOT NULL,
|
|
"token_hash" TEXT NOT NULL,
|
|
"token_prefix" TEXT NOT NULL,
|
|
"role" TEXT NOT NULL DEFAULT 'user',
|
|
"created_by_id" TEXT NOT NULL,
|
|
"user_id" TEXT NOT NULL,
|
|
"last_used_at" TIMESTAMP(3),
|
|
"expires_at" TIMESTAMP(3),
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
CONSTRAINT "api_tokens_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
-- CreateIndex
|
|
CREATE UNIQUE INDEX "api_tokens_token_hash_key" ON "api_tokens"("token_hash");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "api_tokens_token_hash_idx" ON "api_tokens"("token_hash");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "api_tokens_created_by_id_idx" ON "api_tokens"("created_by_id");
|
|
|
|
-- CreateIndex
|
|
CREATE INDEX "api_tokens_user_id_idx" ON "api_tokens"("user_id");
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "api_tokens" ADD CONSTRAINT "api_tokens_created_by_id_fkey" FOREIGN KEY ("created_by_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
|
-- AddForeignKey
|
|
ALTER TABLE "api_tokens" ADD CONSTRAINT "api_tokens_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|