Features added: - Database schema for pages and media files with content types (Rich Text, HTML, Markdown) - Admin API routes for full page CRUD operations - Image upload functionality with file management - Rich text editor using TinyMCE with image insertion - Admin interface for creating/editing pages with SEO options - Dynamic navigation and footer integration - Public page display routes with proper SEO metadata - Support for featured images and content excerpts Admin features: - Create/edit/delete pages with rich content editor - Upload and manage images through media library - Configure pages to appear in navigation or footer - Set page status (Draft, Published, Archived) - SEO title and description management - Real-time preview of content changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
import { NextRequest } from 'next/server';
|
|
import { verify } from 'jsonwebtoken';
|
|
import { prisma } from '@/lib/db';
|
|
|
|
const JWT_SECRET = process.env.JWT_SECRET || 'fallback-secret-key';
|
|
|
|
export interface AdminUser {
|
|
id: string;
|
|
email: string;
|
|
name: string | null;
|
|
role: string;
|
|
}
|
|
|
|
export async function verifyAdminAuth(request: NextRequest): Promise<AdminUser | null> {
|
|
try {
|
|
const authHeader = request.headers.get('authorization');
|
|
if (!authHeader?.startsWith('Bearer ')) {
|
|
return null;
|
|
}
|
|
|
|
const token = authHeader.substring(7);
|
|
|
|
let payload: any;
|
|
try {
|
|
payload = verify(token, JWT_SECRET);
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
|
|
if (!payload.userId) {
|
|
return null;
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: {
|
|
id: payload.userId,
|
|
role: { in: ['admin', 'moderator'] }
|
|
},
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
role: true
|
|
}
|
|
});
|
|
|
|
if (!user) {
|
|
return null;
|
|
}
|
|
|
|
return user;
|
|
} catch (error) {
|
|
console.error('Error verifying admin auth:', error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function hasAdminAccess(user: AdminUser | null): boolean {
|
|
return user?.role === 'admin' || user?.role === 'moderator';
|
|
}
|
|
|
|
export function isSuperAdmin(user: AdminUser | null): boolean {
|
|
return user?.role === 'admin';
|
|
} |