Admin dashboard untuk monitoring user activity, analytics, dan platform statistics di KaelNime.
Access URL: https://your-domain.com/admin/dashboard
Tambahkan email admin ke .env:
ADMIN_EMAILS=almalikulrhakelino@gmail.com,other@admin.comMultiple admins: Pisahkan dengan koma (comma-separated)
Tambahkan environment variable di Vercel:
- Go to: Vercel Dashboard → Project → Settings → Environment Variables
- Add variable:
- Name:
ADMIN_EMAILS - Value:
almalikulrhakelino@gmail.com - Environment: All (Production, Preview, Development)
- Name:
- Save and redeploy
Overview Statistics:
- 👥 Total registered users
- 🎬 Total watch records
- ⏱️ Total watch time (hours)
- 🔥 Active users today
Top Users Leaderboard:
- Ranked by watch time
- Shows level & badge
- Total minutes watched
Recent Activity Feed:
- Last 20 watch activities
- User email, anime watched, time
- Real-time updates
User List Features:
- Complete user information
- Watch statistics per user
- Level & badge display
- Progress to next level (visual bar)
- Last active timestamp
- Episode count
- Sortable by watch time
Columns:
- User (email, name, avatar)
- Level & Badge
- Total watch time
- Episodes watched
- Progress bar to next level
- Last activity date
Activity Feed:
- Last 100 watch activities
- Real-time monitoring
- User who watched
- Anime/episode title
- Timestamp (relative & absolute)
- Watch duration
Activity Stats:
- Today's activities count
- Yesterday's comparison
- This week's total
- User accesses
/admin/*route - Server checks if user is authenticated (NextAuth session)
- Server checks if user email is in
ADMIN_EMAILSlist - If not authenticated → redirect to
/api/auth/signin - If not admin → redirect to
/(home page) - If admin → grant access
All routes under /admin/* are protected:
/admin/dashboard/admin/users/admin/activity
Authorization is server-side only (secure):
- Checked in
AdminLayoutcomponent - Runs before page renders
- No way to bypass via browser dev tools
src/app/
├── admin/
│ ├── layout.jsx # Admin layout with auth check
│ ├── dashboard/
│ │ └── page.jsx # Main dashboard
│ ├── users/
│ │ └── page.jsx # Users list
│ └── activity/
│ └── page.jsx # Activity monitor
│
└── libs/
└── adminAuth.js # Admin auth helper
- Background:
neutral-900(dark) - Cards:
neutral-800withneutral-700borders - Accent:
pink-500/600for important stats - Text:
whiteprimary,neutral-400secondary
- Stat cards with icons
- Tables with hover effects
- Progress bars
- Avatar images
- Relative time formatting
- Responsive layout
# .env
ADMIN_EMAILS=admin1@email.com,admin2@email.com,admin3@email.comCreate new pages under /admin/:
// src/app/admin/analytics/page.jsx
export default async function AdminAnalyticsPage() {
// Your custom analytics
}Add to navigation in layout.jsx:
<Link href="/admin/analytics">📈 Analytics</Link>// Total users
await prisma.user.count()
// Total watch history
await prisma.watchHistory.count()
// Total watch minutes (all users)
await prisma.user.aggregate({ _sum: { totalWatchMinutes: true } })
// Top users by watch time
await prisma.user.findMany({
orderBy: { totalWatchMinutes: 'desc' },
take: 10
})
// Recent activity with user info
await prisma.watchHistory.findMany({
take: 20,
orderBy: { watchedAt: 'desc' },
include: { user: { select: { email, name, level } } }
})Solutions:
- Check
.envhasADMIN_EMAILSset - Verify your logged-in email matches
ADMIN_EMAILS - Restart dev server after changing
.env - For Vercel: Ensure environment variable is set and redeployed
Solutions:
- Check database has data (users, watch history)
- Verify Prisma client is generated (
npx prisma generate) - Check database connection in
.env - Look at server logs for errors
Solutions:
- Add database indexes (userId, watchedAt columns)
- Limit query results (already set to reasonable limits)
- Consider caching for dashboard stats
- Use pagination for large datasets
- Export data to CSV/Excel
- Charts & graphs (watch time trends)
- User search & filter
- Ban/suspend user functionality
- Email notifications for important events
- Real-time updates (WebSocket/SSE)
- Custom date range filters
- Most popular anime analytics
- User engagement metrics
- Admin action logs
- Login with admin email
- Navigate to
/admin/dashboard - View overview statistics
- Click "👥 Users" to see all users
- Click "📜 Activity" to monitor real-time activity
- Use navbar to switch between pages
- Keep admin emails secret - Don't commit to git
- Use strong passwords for admin accounts
- Monitor admin access - Check logs regularly
- Limit admin count - Only trusted users
- Backup database - Before making changes
- Test in staging - Before deploying to production
Version: 1.0
Last Updated: 2025-11-25