feat: initial project setup for Meme Studio
Next.js 14 App Router application for managing homophone pun game levels: - Better Auth with Prisma adapter for authentication - MySQL database with Prisma ORM - Level CRUD operations with drag-and-drop reordering - Tencent COS integration for image uploads - shadcn/ui components with Tailwind CSS - TanStack Query for server state management
This commit is contained in:
86
prisma/schema.prisma
Normal file
86
prisma/schema.prisma
Normal file
@@ -0,0 +1,86 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Level {
|
||||
id String @id @default(uuid())
|
||||
imageUrl String @map("image_url")
|
||||
answer String
|
||||
hint1 String?
|
||||
hint2 String?
|
||||
hint3 String?
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("levels")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
emailVerified Boolean @default(false) @map("email_verified")
|
||||
name String?
|
||||
image String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
sessions Session[]
|
||||
accounts Account[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id
|
||||
expiresAt DateTime @map("expires_at")
|
||||
token String @unique
|
||||
ipAddress String? @map("ip_address")
|
||||
userAgent String? @map("user_agent")
|
||||
userId String @map("user_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("sessions")
|
||||
}
|
||||
|
||||
model Account {
|
||||
id String @id @default(uuid())
|
||||
accountId String @map("account_id")
|
||||
providerId String @map("provider_id")
|
||||
userId String @map("user_id")
|
||||
accessToken String? @map("access_token")
|
||||
refreshToken String? @map("refresh_token")
|
||||
idToken String? @map("id_token")
|
||||
accessTokenExpires DateTime? @map("access_token_expires")
|
||||
refreshTokenExpires DateTime? @map("refresh_token_expires")
|
||||
scope String?
|
||||
password String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("accounts")
|
||||
}
|
||||
|
||||
model Verification {
|
||||
id String @id @default(uuid())
|
||||
identifier String
|
||||
value String
|
||||
expiresAt DateTime @map("expires_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("verifications")
|
||||
}
|
||||
72
prisma/seed.ts
Normal file
72
prisma/seed.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
import { hashPassword } from 'better-auth/crypto'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
async function main() {
|
||||
const email = process.env.ADMIN_EMAIL || 'admin@example.com'
|
||||
const password = process.env.ADMIN_PASSWORD || 'admin123456'
|
||||
|
||||
// Check if admin already exists
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { email },
|
||||
include: { accounts: true },
|
||||
})
|
||||
|
||||
if (existingUser) {
|
||||
// Update password for existing user
|
||||
const hashedPassword = await hashPassword(password)
|
||||
|
||||
if (existingUser.accounts.length > 0) {
|
||||
await prisma.account.update({
|
||||
where: { id: existingUser.accounts[0].id },
|
||||
data: { password: hashedPassword },
|
||||
})
|
||||
} else {
|
||||
await prisma.account.create({
|
||||
data: {
|
||||
accountId: email,
|
||||
providerId: 'credential',
|
||||
userId: existingUser.id,
|
||||
password: hashedPassword,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
console.log(`Admin user password updated: ${email}`)
|
||||
return
|
||||
}
|
||||
|
||||
// Hash password using Better Auth's method
|
||||
const hashedPassword = await hashPassword(password)
|
||||
|
||||
// Create admin user
|
||||
const user = await prisma.user.create({
|
||||
data: {
|
||||
email,
|
||||
name: 'Admin',
|
||||
emailVerified: true,
|
||||
},
|
||||
})
|
||||
|
||||
// Create account with password
|
||||
await prisma.account.create({
|
||||
data: {
|
||||
accountId: email,
|
||||
providerId: 'credential',
|
||||
userId: user.id,
|
||||
password: hashedPassword,
|
||||
},
|
||||
})
|
||||
|
||||
console.log(`Admin user created: ${email}`)
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
Reference in New Issue
Block a user