import { prisma } from "@/lib/prisma" import Navigation from "@/components/Navigation" import Link from "next/link" import { redirect } from "next/navigation" import { getSession } from "@/lib/auth-simple" export default async function AdminDashboard() { console.log('AdminDashboard rendering...') const session = await getSession() console.log('AdminDashboard session:', JSON.stringify(session, null, 2)) if (!session) { console.log('No session found, redirecting to login') redirect("/auth/login") } // Get user role from database since Better Auth doesn't include custom fields in session const userId = session.user?.id || session.user?.userId console.log('Looking for user with ID:', userId) console.log('Session user:', JSON.stringify(session.user, null, 2)) const user = await prisma.user.findUnique({ where: { id: userId } }) console.log('Found user:', user ? 'yes' : 'no') console.log('User role:', user?.role) console.log('User email:', user?.email) // If user doesn't exist or has no role, redirect to login if (!user) { console.log('User not found, redirecting to login') redirect("/auth/login") } // Non-admin users should see a different dashboard if (user.role !== "club_admin") { if (user.playerId) { redirect("/players/" + user.playerId + "/profile") } else { // If playerId is null, redirect to rankings page redirect("/rankings") } } // Get dashboard stats const [playerCount, tournamentCount, matchCount, recentTournaments] = await Promise.all([ prisma.player.count(), prisma.event.count(), prisma.match.count(), prisma.event.findMany({ take: 5, orderBy: { createdAt: "desc" }, }), ]) return (
{/* Page Header */}

Admin Dashboard

Manage your club's tournaments, players, and matches.

{/* Stats Grid */}
Total Players
{playerCount}
Tournaments
{tournamentCount}
Matches Played
{matchCount}
{/* Quick Actions */}

Quick Actions

New Tournament Import CSV View Rankings All Tournaments
{/* Recent Tournaments */}

Recent Tournaments

{recentTournaments.length > 0 ? (
    {recentTournaments.map((tournament) => (
  • {tournament.name}

    {tournament.status}

    View
  • ))}
) : (

No tournaments yet.

)}
{/* Player Directory Preview */}

Player Directory

View All
{/* This would be populated with actual player data in a real implementation */}

View all players in the rankings page.

) }