Added Better auth mitation
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
"@prisma/client": "^7",
|
||||
"@repo/api-contract": "workspace:*",
|
||||
"@supabase/supabase-js": "2.101.1",
|
||||
"better-auth": "^1.6.4",
|
||||
"dotenv": "^17.4.1",
|
||||
"hono": "4.12.10",
|
||||
"nodemailer": "^8.0.5",
|
||||
@@ -33,4 +34,4 @@
|
||||
"@types/bun": "latest",
|
||||
"@types/nodemailer": "^8.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
62
apps/backend/prisma/auth.prisma
Normal file
62
apps/backend/prisma/auth.prisma
Normal file
@@ -0,0 +1,62 @@
|
||||
model User {
|
||||
id String @id
|
||||
name String
|
||||
email String
|
||||
emailVerified Boolean @default(false)
|
||||
image String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
sessions Session[]
|
||||
accounts Account[]
|
||||
|
||||
@@unique([email])
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id
|
||||
expiresAt DateTime
|
||||
token String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ipAddress String?
|
||||
userAgent String?
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([token])
|
||||
@@index([userId])
|
||||
@@map("sessions")
|
||||
}
|
||||
|
||||
model Account {
|
||||
id String @id
|
||||
accountId String
|
||||
providerId String
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
accessToken String?
|
||||
refreshToken String?
|
||||
idToken String?
|
||||
accessTokenExpiresAt DateTime?
|
||||
refreshTokenExpiresAt DateTime?
|
||||
scope String?
|
||||
password String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([userId])
|
||||
@@map("accounts")
|
||||
}
|
||||
|
||||
model Verification {
|
||||
id String @id
|
||||
identifier String
|
||||
value String
|
||||
expiresAt DateTime
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([identifier])
|
||||
@@map("verification")
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
model Complex {
|
||||
id String @id @db.Uuid
|
||||
complexName String @map("complex_name")
|
||||
physicalAddress String? @map("physical_address") @db.VarChar(200)
|
||||
city String? @map("city") @db.VarChar(100)
|
||||
state String? @map("state") @db.VarChar(100)
|
||||
country String? @map("country") @db.VarChar(100)
|
||||
complexSlug String @unique @map("complex_slug")
|
||||
adminEmail String @map("admin_email")
|
||||
planCode String? @map("plan_code") @db.VarChar(10)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
plan Plan? @relation(fields: [planCode], references: [code])
|
||||
users ComplexUser[]
|
||||
courts Court[]
|
||||
id String @id @db.Uuid
|
||||
complexName String @map("complex_name")
|
||||
physicalAddress String? @map("physical_address") @db.VarChar(200)
|
||||
city String? @map("city") @db.VarChar(100)
|
||||
state String? @map("state") @db.VarChar(100)
|
||||
country String? @map("country") @db.VarChar(100)
|
||||
complexSlug String @unique @map("complex_slug")
|
||||
adminEmail String @map("admin_email")
|
||||
planCode String? @map("plan_code") @db.VarChar(10)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
plan Plan? @relation(fields: [planCode], references: [code])
|
||||
// users ComplexUser[]
|
||||
courts Court[]
|
||||
|
||||
@@index([planCode])
|
||||
@@index([complexSlug])
|
||||
@@ -21,17 +21,18 @@ model Complex {
|
||||
|
||||
enum ComplexUserRole {
|
||||
ADMIN
|
||||
EMPLOYEE
|
||||
}
|
||||
|
||||
model ComplexUser {
|
||||
complexId String @map("complex_id") @db.Uuid
|
||||
userId String @map("user_id") @db.Uuid
|
||||
role ComplexUserRole @default(ADMIN)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
complex Complex @relation(fields: [complexId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
// model ComplexUser {
|
||||
// complexId String @map("complex_id") @db.Uuid
|
||||
// userId String @map("user_id") @db.Uuid
|
||||
// role ComplexUserRole @default(ADMIN)
|
||||
// createdAt DateTime @default(now()) @map("created_at")
|
||||
// complex Complex @relation(fields: [complexId], references: [id], onDelete: Cascade)
|
||||
// user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([complexId, userId])
|
||||
@@index([userId])
|
||||
@@map("complex_users")
|
||||
}
|
||||
// @@id([complexId, userId])
|
||||
// @@index([userId])
|
||||
// @@map("complex_users")
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The primary key for the `users` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
- You are about to drop the column `created_at` on the `users` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `full_name` on the `users` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `supabase_user_id` on the `users` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `updated_at` on the `users` table. All the data in the column will be lost.
|
||||
- You are about to drop the `complex_users` table. If the table is not empty, all the data it contains will be lost.
|
||||
- Added the required column `name` to the `users` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `updatedAt` to the `users` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterEnum
|
||||
ALTER TYPE "ComplexUserRole" ADD VALUE 'EMPLOYEE';
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "complex_users" DROP CONSTRAINT "complex_users_complex_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "complex_users" DROP CONSTRAINT "complex_users_user_id_fkey";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "users_supabase_user_id_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" DROP CONSTRAINT "users_pkey",
|
||||
DROP COLUMN "created_at",
|
||||
DROP COLUMN "full_name",
|
||||
DROP COLUMN "supabase_user_id",
|
||||
DROP COLUMN "updated_at",
|
||||
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "emailVerified" BOOLEAN NOT NULL DEFAULT false,
|
||||
ADD COLUMN "image" TEXT,
|
||||
ADD COLUMN "name" TEXT NOT NULL,
|
||||
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
ALTER COLUMN "id" SET DATA TYPE TEXT,
|
||||
ADD CONSTRAINT "users_pkey" PRIMARY KEY ("id");
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "complex_users";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "sessions" (
|
||||
"id" TEXT NOT NULL,
|
||||
"expiresAt" TIMESTAMP(3) NOT NULL,
|
||||
"token" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
"ipAddress" TEXT,
|
||||
"userAgent" TEXT,
|
||||
"userId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "sessions_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "accounts" (
|
||||
"id" TEXT NOT NULL,
|
||||
"accountId" TEXT NOT NULL,
|
||||
"providerId" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"accessToken" TEXT,
|
||||
"refreshToken" TEXT,
|
||||
"idToken" TEXT,
|
||||
"accessTokenExpiresAt" TIMESTAMP(3),
|
||||
"refreshTokenExpiresAt" TIMESTAMP(3),
|
||||
"scope" TEXT,
|
||||
"password" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "verification" (
|
||||
"id" TEXT NOT NULL,
|
||||
"identifier" TEXT NOT NULL,
|
||||
"value" TEXT NOT NULL,
|
||||
"expiresAt" TIMESTAMP(3) NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "verification_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "sessions_userId_idx" ON "sessions"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "sessions_token_key" ON "sessions"("token");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "accounts_userId_idx" ON "accounts"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "verification_identifier_idx" ON "verification"("identifier");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "accounts" ADD CONSTRAINT "accounts_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -1,11 +1,11 @@
|
||||
model User {
|
||||
id String @id @db.Uuid
|
||||
supabaseUserId String @unique @map("supabase_user_id") @db.Uuid
|
||||
email String @unique
|
||||
fullName String @map("full_name")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
complexes ComplexUser[]
|
||||
// model User {
|
||||
// id String @id @db.Uuid
|
||||
// supabaseUserId String @unique @map("supabase_user_id") @db.Uuid
|
||||
// email String @unique
|
||||
// fullName String @map("full_name")
|
||||
// createdAt DateTime @default(now()) @map("created_at")
|
||||
// updatedAt DateTime @updatedAt @map("updated_at")
|
||||
// complexes ComplexUser[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
// @@map("users")
|
||||
// }
|
||||
|
||||
@@ -3,13 +3,18 @@
|
||||
"ignoreDeprecations": "6.0",
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"types": ["bun"],
|
||||
"types": [
|
||||
"bun"
|
||||
],
|
||||
"baseUrl": ".",
|
||||
"moduleResolution": "bundler",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "hono/jsx"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user