Fix Next.js 15 compatibility and TypeScript errors

- Update API route handlers to use async params for Next.js 15 compatibility
- Fix MUI DataGrid deprecated props (pageSize -> initialState.pagination)
- Replace Material-UI Grid components with Box for better compatibility
- Fix admin authentication system with proper request parameters
- Update permission constants to match available AdminPermission enum values
- Add missing properties to Page interface for type safety
- Update .gitignore to exclude venv/, import logs, and large data directories
- Optimize Next.js config to reduce memory usage during builds

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-24 09:54:13 +00:00
parent b0dd6c1a4b
commit 4303e48fac
25 changed files with 269 additions and 91 deletions

View File

@@ -30,10 +30,10 @@ interface PageData {
}
interface PageProps {
params: {
params: Promise<{
locale: string
slug: string
}
}>
}
async function getPageData(slug: string): Promise<PageData | null> {
@@ -55,7 +55,8 @@ async function getPageData(slug: string): Promise<PageData | null> {
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const page = await getPageData(params.slug)
const resolvedParams = await params
const page = await getPageData(resolvedParams.slug)
if (!page) {
return {
@@ -184,14 +185,15 @@ function renderContent(content: string, contentType: string) {
}
export default async function PageView({ params }: PageProps) {
const page = await getPageData(params.slug)
const resolvedParams = await params
const page = await getPageData(resolvedParams.slug)
if (!page) {
notFound()
}
const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleDateString(params.locale, {
return new Date(dateString).toLocaleDateString(resolvedParams.locale, {
year: 'numeric',
month: 'long',
day: 'numeric'
@@ -207,7 +209,7 @@ export default async function PageView({ params }: PageProps) {
underline="hover"
sx={{ display: 'flex', alignItems: 'center' }}
color="inherit"
href={`/${params.locale}`}
href={`/${resolvedParams.locale}`}
>
<HomeIcon sx={{ mr: 0.5 }} fontSize="inherit" />
Home

View File

@@ -40,6 +40,8 @@ interface Page {
id: string;
title: string;
slug: string;
content: string;
contentType: 'RICH_TEXT' | 'HTML' | 'MARKDOWN';
status: 'DRAFT' | 'PUBLISHED' | 'ARCHIVED';
showInNavigation: boolean;
showInFooter: boolean;
@@ -319,8 +321,13 @@ export default function PagesManagement() {
columns={columns}
loading={loading}
autoHeight
pageSize={25}
disableSelectionOnClick
initialState={{
pagination: {
paginationModel: { pageSize: 25, page: 0 }
}
}}
pageSizeOptions={[25, 50, 100]}
disableRowSelectionOnClick
sx={{
'& .MuiDataGrid-cell': {
borderBottom: '1px solid #f0f0f0'

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.VIEW_ANALYTICS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_ANALYTICS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.VIEW_ANALYTICS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_ANALYTICS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.VIEW_ANALYTICS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_ANALYTICS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.VIEW_ANALYTICS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_ANALYTICS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -4,7 +4,7 @@ import { getCurrentAdmin } from '@/lib/admin-auth';
export const runtime = 'nodejs';
export async function GET() {
export async function GET(request: Request) {
try {
console.log('Admin auth check - starting...');
@@ -21,7 +21,7 @@ export async function GET() {
);
}
const admin = await getCurrentAdmin();
const admin = await getCurrentAdmin(request as any);
console.log('Admin user found:', !!admin);
if (!admin) {

View File

@@ -9,8 +9,8 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_CHAT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -106,8 +106,8 @@ export async function PUT(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.WRITE_CHAT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -168,8 +168,8 @@ export async function DELETE(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.DELETE_CHAT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_CHAT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -9,8 +9,8 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.DELETE_CONTENT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -80,8 +80,8 @@ export async function PUT(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.DELETE_CONTENT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -142,8 +142,8 @@ export async function DELETE(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.DELETE_CONTENT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MODERATE_CONTENT)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.DELETE_CONTENT)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -4,7 +4,7 @@ import { verifyAdminAuth } from '@/lib/admin-auth';
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } }
{ params }: { params: Promise<{ id: string }> }
) {
try {
const adminUser = await verifyAdminAuth(request);
@@ -12,8 +12,9 @@ export async function GET(
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const resolvedParams = await params;
const page = await prisma.page.findUnique({
where: { id: params.id },
where: { id: resolvedParams.id },
include: {
creator: { select: { name: true, email: true } },
updater: { select: { name: true, email: true } }
@@ -42,7 +43,7 @@ export async function GET(
export async function PUT(
request: NextRequest,
{ params }: { params: { id: string } }
{ params }: { params: Promise<{ id: string }> }
) {
try {
const adminUser = await verifyAdminAuth(request);
@@ -50,6 +51,7 @@ export async function PUT(
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const resolvedParams = await params;
const body = await request.json();
const {
title,
@@ -69,7 +71,7 @@ export async function PUT(
// Check if page exists
const existingPage = await prisma.page.findUnique({
where: { id: params.id }
where: { id: resolvedParams.id }
});
if (!existingPage) {
@@ -85,7 +87,7 @@ export async function PUT(
where: { slug }
});
if (conflictingPage && conflictingPage.id !== params.id) {
if (conflictingPage && conflictingPage.id !== resolvedParams.id) {
return NextResponse.json(
{ success: false, error: 'A page with this slug already exists' },
{ status: 400 }
@@ -94,7 +96,7 @@ export async function PUT(
}
const updatedPage = await prisma.page.update({
where: { id: params.id },
where: { id: resolvedParams.id },
data: {
title,
slug,
@@ -137,7 +139,7 @@ export async function PUT(
export async function DELETE(
request: NextRequest,
{ params }: { params: { id: string } }
{ params }: { params: Promise<{ id: string }> }
) {
try {
const adminUser = await verifyAdminAuth(request);
@@ -145,8 +147,9 @@ export async function DELETE(
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const resolvedParams = await params;
const page = await prisma.page.findUnique({
where: { id: params.id }
where: { id: resolvedParams.id }
});
if (!page) {
@@ -157,7 +160,7 @@ export async function DELETE(
}
await prisma.page.delete({
where: { id: params.id }
where: { id: resolvedParams.id }
});
return NextResponse.json({

View File

@@ -4,9 +4,9 @@ import { getCurrentAdmin } from '@/lib/admin-auth';
export const runtime = 'nodejs';
export async function GET() {
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
const admin = await getCurrentAdmin(request as any);
if (!admin) {
return NextResponse.json(
{ error: 'Unauthorized' },

View File

@@ -9,8 +9,8 @@ export const runtime = 'nodejs';
export async function POST(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MANAGE_SYSTEM)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.SYSTEM_BACKUP)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -94,8 +94,8 @@ export async function POST(request: Request) {
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MANAGE_SYSTEM)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.SYSTEM_BACKUP)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MANAGE_SYSTEM)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.SYSTEM_HEALTH)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -9,8 +9,8 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.VIEW_USERS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_USERS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -101,8 +101,8 @@ export async function PUT(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MANAGE_USERS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.WRITE_USERS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
@@ -165,8 +165,8 @@ export async function DELETE(
{ params }: { params: Promise<{ id: string }> }
) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.MANAGE_USERS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.DELETE_USERS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -6,8 +6,8 @@ export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin();
if (!admin || !hasPermission(admin, AdminPermission.VIEW_USERS)) {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_USERS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }

View File

@@ -3,12 +3,13 @@ import { prisma } from '@/lib/db';
export async function GET(
request: NextRequest,
{ params }: { params: { slug: string } }
{ params }: { params: Promise<{ slug: string }> }
) {
try {
const resolvedParams = await params;
const page = await prisma.page.findUnique({
where: {
slug: params.slug,
slug: resolvedParams.slug,
status: 'PUBLISHED'
},
select: {