Skip to content

Conversation

@jeromehardaway
Copy link
Contributor

BREAKING CHANGES:

  • Admin pages now require server-side authentication
  • Hardcoded admin email replaced with database role checks
  • All admin access now requires ADMIN role from database

Security Improvements:

  • Convert all admin pages from getStaticProps to getServerSideProps
  • Add server-side authentication checks before rendering admin pages
  • Block unauthorized access at server level (not client-side)
  • Replace hardcoded 'jeromehardaway' email with role-based checks

Pages Updated:

  • admin/users.tsx: Fetch real user data from database, added role badges
  • admin/courses.tsx: Fetch real course data with enrollment counts
  • admin/index.tsx: Display real dashboard statistics, remove dev-session
  • admin/blog-images.tsx: Add server-side auth protection
  • courses/index.tsx: Use role check for admin dashboard link

Database Integration:

  • admin/users: Query users with enrollment counts
  • admin/courses: Query courses with module/enrollment counts
  • admin/index: Aggregate platform statistics from database

This fixes critical security vulnerability where admin pages were:

  1. Publicly accessible as static pages
  2. Using client-side auth checks (bypassable)
  3. Displaying mock data instead of real database data
  4. Hardcoding admin access to single GitHub user

…d access

BREAKING CHANGES:
- Admin pages now require server-side authentication
- Hardcoded admin email replaced with database role checks
- All admin access now requires ADMIN role from database

Security Improvements:
- Convert all admin pages from getStaticProps to getServerSideProps
- Add server-side authentication checks before rendering admin pages
- Block unauthorized access at server level (not client-side)
- Replace hardcoded 'jeromehardaway' email with role-based checks

Pages Updated:
- admin/users.tsx: Fetch real user data from database, added role badges
- admin/courses.tsx: Fetch real course data with enrollment counts
- admin/index.tsx: Display real dashboard statistics, remove dev-session
- admin/blog-images.tsx: Add server-side auth protection
- courses/index.tsx: Use role check for admin dashboard link

Database Integration:
- admin/users: Query users with enrollment counts
- admin/courses: Query courses with module/enrollment counts
- admin/index: Aggregate platform statistics from database

This fixes critical security vulnerability where admin pages were:
1. Publicly accessible as static pages
2. Using client-side auth checks (bypassable)
3. Displaying mock data instead of real database data
4. Hardcoding admin access to single GitHub user
@jeromehardaway jeromehardaway self-assigned this Dec 31, 2025
@vercel
Copy link
Contributor

vercel bot commented Dec 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
vets-who-code-app Ready Ready Preview, Comment Dec 31, 2025 6:06am

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements critical security improvements by replacing hardcoded admin authentication with role-based access control and converting client-side admin pages to server-side rendering with proper authentication checks.

Key Changes:

  • Replaced hardcoded email check with database role-based authentication system
  • Converted all admin pages from getStaticProps to getServerSideProps for server-side protection
  • Integrated real database queries to replace mock data across admin pages

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/pages/courses/index.tsx Updated admin access check from hardcoded email to role-based verification
src/pages/admin/users.tsx Converted to server-side rendering with database integration for user management
src/pages/admin/index.tsx Replaced mock statistics with real database aggregations and removed dev-session logic
src/pages/admin/courses.tsx Implemented server-side authentication and real course data from database
src/pages/admin/blog-images.tsx Added server-side authentication protection to replace client-side checks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to +34
const completionRate = stats.totalEnrollments > 0
? Math.round((stats.completedEnrollments / stats.totalEnrollments) * 100)
: 0;
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The completion rate calculation is defined in the component body and will be recalculated on every render. Consider moving this calculation to the server-side in getServerSideProps where the stats are already being computed, or memoize it with useMemo if it needs to be client-side.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

🔍 Code Quality Score Breakdown:

  • 📖 Readability: 2/10
  • 📈 Scalability: 5/10
  • 🚀 Performance: 5/10
  • 🛠️ Maintainability: 8/10
  • ✅ Overall Score: 5.0/10

💡 Recommendations:

  • 🧹 Reduce ESLint warnings to improve readability.
  • 📦 Break up complex functions or components.
  • ⚙️ Consider splitting large files or lazy-loading.
  • 🔁 Refactor to increase your overall score next cycle.

- Add explicit permissions block for workflow scoping
- Use VWC_GITHUB_TOKEN secret instead of default GITHUB_TOKEN
- Fixes build failure when fetching GitHub project data
@github-actions
Copy link

🔍 Code Quality Score Breakdown:

  • 📖 Readability: 2/10
  • 📈 Scalability: 5/10
  • 🚀 Performance: 5/10
  • 🛠️ Maintainability: 8/10
  • ✅ Overall Score: 5.0/10

💡 Recommendations:

  • 🧹 Reduce ESLint warnings to improve readability.
  • 📦 Break up complex functions or components.
  • ⚙️ Consider splitting large files or lazy-loading.
  • 🔁 Refactor to increase your overall score next cycle.

@jeromehardaway jeromehardaway merged commit c59e11a into master Dec 31, 2025
5 checks passed
@jeromehardaway jeromehardaway deleted the fix/admin-authorization branch December 31, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants