mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 13:52:16 +01:00
- Implemented API session retrieval in `lib/api-auth.ts` to manage user sessions. - Created authentication options in `lib/auth-options.ts` using NextAuth.js with credentials provider. - Added migration scripts to create necessary tables for authentication in `migrations/0002_create_auth_tables.sql` and `prisma/migrations/20250601033219_add_nextauth_tables/migration.sql`. - Configured ESLint with Next.js and TypeScript support in `eslint.config.mjs`. - Updated Next.js configuration in `next.config.ts` for Cloudflare compatibility. - Defined Cloudflare Worker configuration in `open-next.config.ts` and `wrangler.jsonc`. - Enhanced type definitions for authentication in `types/auth.d.ts`. - Created a Cloudflare Worker entry point in `src/index.ts.backup` to handle API requests and responses.
101 lines
2.7 KiB
Plaintext
101 lines
2.7 KiB
Plaintext
// Database schema, one company = one org, linked to users and CSV config
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
previewFeatures = ["driverAdapters"]
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
model Company {
|
|
id String @id @default(uuid())
|
|
name String
|
|
csvUrl String // where to fetch CSV
|
|
csvUsername String? // for basic auth
|
|
csvPassword String?
|
|
sentimentAlert Float? // e.g. alert threshold for negative chats
|
|
dashboardOpts String? // JSON blob for per-company dashboard preferences
|
|
users User[]
|
|
sessions Session[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
password String // hashed, use bcrypt
|
|
company Company @relation(fields: [companyId], references: [id])
|
|
companyId String
|
|
role String // 'admin' | 'user' | 'auditor'
|
|
resetToken String?
|
|
resetTokenExpiry DateTime?
|
|
|
|
// NextAuth fields
|
|
accounts Account[]
|
|
sessions UserSession[]
|
|
emailVerified DateTime?
|
|
image String?
|
|
}
|
|
|
|
// NextAuth models
|
|
model Account {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
type String
|
|
provider String
|
|
providerAccountId String
|
|
refresh_token String?
|
|
access_token String?
|
|
expires_at Int?
|
|
token_type String?
|
|
scope String?
|
|
id_token String?
|
|
session_state String?
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([provider, providerAccountId])
|
|
}
|
|
|
|
model UserSession {
|
|
id String @id @default(cuid())
|
|
sessionToken String @unique
|
|
userId String
|
|
expires DateTime
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model VerificationToken {
|
|
identifier String
|
|
token String @unique
|
|
expires DateTime
|
|
|
|
@@unique([identifier, token])
|
|
}
|
|
|
|
model Session {
|
|
id String @id
|
|
company Company @relation(fields: [companyId], references: [id])
|
|
companyId String
|
|
startTime DateTime
|
|
endTime DateTime
|
|
ipAddress String?
|
|
country String?
|
|
language String?
|
|
messagesSent Int?
|
|
sentiment Float?
|
|
escalated Boolean?
|
|
forwardedHr Boolean?
|
|
fullTranscriptUrl String?
|
|
transcriptContent String? // Added to store the fetched transcript
|
|
avgResponseTime Float?
|
|
tokens Int?
|
|
tokensEur Float?
|
|
category String?
|
|
initialMsg String?
|
|
createdAt DateTime @default(now())
|
|
}
|