Replace Clerk with self-contained JWT auth (bcryptjs + jose), remove all external auth dependencies. Add full i18n system with Chinese as default language and English toggle — React Context + JSON dictionaries, no external i18n library. Auth: - Add passwordHash to User model, generate JWT secret - Create /api/auth/register, login, logout, me endpoints - Rewrite proxy.ts middleware for custom session validation - Add AuthProvider + useAuth hook, sign-in/sign-up pages - Wire auth into layout and all API routes i18n: - React Context I18nProvider with localStorage + cookie persistence - dictionaries/zh.ts (default) and dictionaries/en.ts - LanguageSwitcher component, server-side createServerT() utility - CJK font stack via [lang="zh"] CSS selector - HTML lang attribute synced on language change - All pages, components, TabBar, StageBadge translated - Engine fallback strings (reflection-analyzer, summary-generator) - API routes pass locale from cookie to engines Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
128 lines
3.6 KiB
Plaintext
128 lines
3.6 KiB
Plaintext
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
}
|
|
|
|
enum TaskType {
|
|
attention_training
|
|
emotion_awareness
|
|
stress_regulation
|
|
cognitive_clarity
|
|
integration
|
|
}
|
|
|
|
enum TaskStatus {
|
|
pending
|
|
completed
|
|
expired
|
|
}
|
|
|
|
enum RewardEventType {
|
|
daily_completion
|
|
streak_3
|
|
streak_7
|
|
streak_14
|
|
streak_30
|
|
stage_up
|
|
first_session
|
|
}
|
|
|
|
model User {
|
|
id String @id @default(uuid())
|
|
email String @unique
|
|
passwordHash String? @map("password_hash")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
state UserState? @relation("UserState")
|
|
sessions Session[]
|
|
tasks Task[]
|
|
rewardEvents RewardEvent[]
|
|
weeklySummary WeeklySummary?
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model UserState {
|
|
id String @id @default(uuid())
|
|
userId String @unique @map("user_id")
|
|
attentionLevel Int @default(50) @map("attention_level")
|
|
emotionStability Int @default(50) @map("emotion_stability")
|
|
stressLevel Int @default(50) @map("stress_level")
|
|
practiceStage Int @default(0) @map("practice_stage")
|
|
consistencyScore Int @default(0) @map("consistency_score")
|
|
streakDays Int @default(0) @map("streak_days")
|
|
totalSessionsCompleted Int @default(0) @map("total_sessions_completed")
|
|
onboardingCompleted Boolean @default(false) @map("onboarding_completed")
|
|
lastSessionDate DateTime? @map("last_session_date")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
user User @relation("UserState", fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@map("user_states")
|
|
}
|
|
|
|
model Session {
|
|
id String @id @default(uuid())
|
|
userId String @map("user_id")
|
|
taskType TaskType @map("task_type")
|
|
taskDescription String @map("task_description")
|
|
durationSeconds Int @default(300) @map("duration_seconds")
|
|
completed Boolean @default(false)
|
|
focusScore Int? @map("focus_score")
|
|
emotionScore Int? @map("emotion_score")
|
|
notes String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId, createdAt])
|
|
@@map("sessions")
|
|
}
|
|
|
|
model Task {
|
|
id String @id @default(uuid())
|
|
userId String @map("user_id")
|
|
type TaskType
|
|
difficulty Int @default(1)
|
|
duration Int @default(5)
|
|
description String
|
|
reasonJson String @default("{}") @map("reason_json")
|
|
status TaskStatus @default(pending)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId, createdAt])
|
|
@@index([userId, status])
|
|
@@map("tasks")
|
|
}
|
|
|
|
model RewardEvent {
|
|
id String @id @default(uuid())
|
|
userId String @map("user_id")
|
|
type RewardEventType
|
|
message String
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId, createdAt])
|
|
@@map("reward_events")
|
|
}
|
|
|
|
model WeeklySummary {
|
|
id String @id @default(uuid())
|
|
userId String @unique @map("user_id")
|
|
summary String?
|
|
weekStart DateTime @map("week_start")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@map("weekly_summaries")
|
|
}
|