2
0

feat(user): Revokable API tokens

This commit is contained in:
Baptiste Arnaud
2022-06-03 13:20:19 +02:00
parent e5d7f1d1ce
commit a0929c492b
20 changed files with 472 additions and 43 deletions

View File

@ -0,0 +1,23 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- CreateTable
CREATE TABLE "ApiToken" (
"id" TEXT NOT NULL,
"token" TEXT NOT NULL,
"name" TEXT NOT NULL,
"ownerId" TEXT NOT NULL,
"lastUsedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "ApiToken_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "ApiToken_token_key" ON "ApiToken"("token");
-- AddForeignKey
ALTER TABLE "ApiToken" ADD CONSTRAINT "ApiToken_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
INSERT INTO "ApiToken" (id, "ownerId", token, name) SELECT uuid_generate_v4(), u.id, u."apiToken", 'Default' FROM "User" u;
ALTER TABLE "User" DROP COLUMN "apiToken";

View File

@ -48,7 +48,7 @@ model User {
image String?
accounts Account[]
sessions Session[]
apiToken String?
apiTokens ApiToken[]
CollaboratorsOnTypebots CollaboratorsOnTypebots[]
company String?
onboardingCategories String[]
@ -56,6 +56,16 @@ model User {
workspaces MemberInWorkspace[]
}
model ApiToken {
id String @id @default(cuid())
token String @unique
name String
ownerId String
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
lastUsedAt DateTime @default(now())
createdAt DateTime @default(now())
}
model Workspace {
id String @id @default(cuid())
name String
@ -64,7 +74,7 @@ model Workspace {
folders DashboardFolder[]
typebots Typebot[]
createdAt DateTime @default(now())
plan Plan @default(FREE)
plan Plan @default(FREE)
stripeId String? @unique
customDomains CustomDomain[]
credentials Credentials[]
@ -102,15 +112,15 @@ enum GraphNavigation {
}
model CustomDomain {
name String @id
createdAt DateTime @default(now())
name String @id
createdAt DateTime @default(now())
workspaceId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
}
model Credentials {
id String @id @default(cuid())
createdAt DateTime @default(now())
id String @id @default(cuid())
createdAt DateTime @default(now())
workspaceId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
data String // Encrypted data