feat: authentication!!!!!

This commit is contained in:
2026-03-31 23:31:16 +02:00
parent 6baa0b2822
commit 4573557abc
7 changed files with 302 additions and 14 deletions

View File

@@ -0,0 +1,40 @@
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"publicKey" TEXT NOT NULL,
"slackId" TEXT NOT NULL,
"username" TEXT NOT NULL,
"email" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Session" (
"id" SERIAL NOT NULL,
"userId" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "User_publicKey_key" ON "User"("publicKey");
-- CreateIndex
CREATE UNIQUE INDEX "User_slackId_key" ON "User"("slackId");
-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
-- CreateIndex
CREATE UNIQUE INDEX "Session_userId_key" ON "Session"("userId");
-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -0,0 +1,29 @@
/*
Warnings:
- A unique constraint covering the columns `[hcaId]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- Added the required column `hcaId` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "hcaId" TEXT NOT NULL;
-- CreateTable
CREATE TABLE "CreateAccount" (
"id" SERIAL NOT NULL,
"code" TEXT NOT NULL,
"publicKey" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "CreateAccount_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "CreateAccount_code_key" ON "CreateAccount"("code");
-- CreateIndex
CREATE UNIQUE INDEX "CreateAccount_publicKey_key" ON "CreateAccount"("publicKey");
-- CreateIndex
CREATE UNIQUE INDEX "User_hcaId_key" ON "User"("hcaId");

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View File

@@ -11,3 +11,35 @@ generator client {
datasource db {
provider = "postgresql"
}
model User {
id Int @id @default(autoincrement())
hcaId String @unique
publicKey String @unique
slackId String @unique
username String @unique
email String @unique
sessions Session[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// if userid is null, the session is anonymous and will be authenticated.
model Session {
id Int @id @default(autoincrement())
userId Int? @unique
user User? @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model CreateAccount {
id Int @id @default(autoincrement())
code String @unique
publicKey String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}