From 697da088d4edef0c296dd15c02dd2d847b92f1e9 Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Sun, 21 Sep 2025 22:42:47 +0100 Subject: [PATCH] Fixed admin count endpoint --- backend/src/routes/authRoutes.js | 13 +------------ frontend/src/contexts/AuthContext.jsx | 4 +--- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/backend/src/routes/authRoutes.js b/backend/src/routes/authRoutes.js index e97c8d6..ce0d177 100644 --- a/backend/src/routes/authRoutes.js +++ b/backend/src/routes/authRoutes.js @@ -10,20 +10,9 @@ const { v4: uuidv4 } = require('uuid'); const router = express.Router(); const prisma = new PrismaClient(); -// Check if any admin users exist (for first-time setup) - INTERNAL ONLY +// Check if any admin users exist (for first-time setup) router.get('/check-admin-users', async (req, res) => { try { - // Only allow this check from localhost or internal requests - const clientIP = req.ip || req.connection.remoteAddress; - const isLocalhost = clientIP === '127.0.0.1' || clientIP === '::1' || clientIP === '::ffff:127.0.0.1'; - - if (!isLocalhost && !req.headers.host?.includes('localhost')) { - return res.status(403).json({ - error: 'Access denied - admin check only available locally', - hasAdminUsers: true // Assume admin exists for security - }); - } - const adminCount = await prisma.users.count({ where: { role: 'admin' } }); diff --git a/frontend/src/contexts/AuthContext.jsx b/frontend/src/contexts/AuthContext.jsx index 6bda081..4f729fc 100644 --- a/frontend/src/contexts/AuthContext.jsx +++ b/frontend/src/contexts/AuthContext.jsx @@ -232,9 +232,7 @@ export const AuthProvider = ({ children }) => { if (response.ok) { const data = await response.json() console.log('Admin check response:', data) // Debug log - // TEMPORARY DEBUG: Force admin setup for testing - // setNeedsFirstTimeSetup(!data.hasAdminUsers) - setNeedsFirstTimeSetup(true) // Force setup for testing + setNeedsFirstTimeSetup(!data.hasAdminUsers) } else { console.log('Admin check failed:', response.status, response.statusText) // Debug log // If endpoint doesn't exist or fails, assume setup is needed