diff --git a/scripts/create-super-admin-auth.ts b/scripts/create-super-admin-auth.ts index 5465261f..aa4e8c25 100644 --- a/scripts/create-super-admin-auth.ts +++ b/scripts/create-super-admin-auth.ts @@ -20,7 +20,7 @@ const auth = getAuth(app); async function createSuperAdmin() { try { console.log("Creating Super Admin Auth user..."); - await createUserWithEmailAndPassword(auth, "ap8548328@gmail.com", "Aditya@2006@#"); + await createUserWithEmailAndPassword(auth, process.env.SUPER_ADMIN_EMAIL as string, process.env.SUPER_ADMIN_PASSWORD as string); console.log("Super Admin Auth user created successfully."); process.exit(0); } catch (error: any) { diff --git a/scripts/create-super-admin-simple.js b/scripts/create-super-admin-simple.js index f93267a3..3ebecc4f 100644 --- a/scripts/create-super-admin-simple.js +++ b/scripts/create-super-admin-simple.js @@ -16,8 +16,8 @@ initializeApp({ const auth = getAuth(); const db = getFirestore(); -const SUPER_ADMIN_EMAIL = "devpathind.community@gmail.com"; -const SUPER_ADMIN_PASSWORD = "Aditya@2006@#"; +const SUPER_ADMIN_EMAIL = process.env.SUPER_ADMIN_EMAIL; +const SUPER_ADMIN_PASSWORD = process.env.SUPER_ADMIN_PASSWORD; async function createSuperAdmin() { console.log(`Creating/Updating Super Admin: ${SUPER_ADMIN_EMAIL}...`); diff --git a/scripts/create-super-admin.js b/scripts/create-super-admin.js index f513f0aa..2c7fe50b 100644 --- a/scripts/create-super-admin.js +++ b/scripts/create-super-admin.js @@ -14,8 +14,8 @@ initializeApp({ const auth = getAuth(); const db = getFirestore(); -const SUPER_ADMIN_EMAIL = "devpathind.community@gmail.com"; -const SUPER_ADMIN_PASSWORD = "Aditya@2006@#"; +const SUPER_ADMIN_EMAIL = process.env.SUPER_ADMIN_EMAIL; +const SUPER_ADMIN_PASSWORD = process.env.SUPER_ADMIN_PASSWORD; async function createSuperAdmin() { console.log(`Creating/Updating Super Admin: ${SUPER_ADMIN_EMAIL}...`); diff --git a/scripts/create-super-admin.ts b/scripts/create-super-admin.ts index 73d826da..b4d90b9f 100644 --- a/scripts/create-super-admin.ts +++ b/scripts/create-super-admin.ts @@ -15,8 +15,8 @@ initializeApp({ const auth = getAuth(); const db = getFirestore(); -const SUPER_ADMIN_EMAIL = "devpathind.community@gmail.com"; -const SUPER_ADMIN_PASSWORD = "Aditya@2006@#"; +const SUPER_ADMIN_EMAIL = process.env.SUPER_ADMIN_EMAIL; +const SUPER_ADMIN_PASSWORD = process.env.SUPER_ADMIN_PASSWORD; async function createSuperAdmin() { console.log(`Creating/Updating Super Admin: ${SUPER_ADMIN_EMAIL}...`); diff --git a/scripts/full-recalc.ts b/scripts/full-recalc.ts index e9adf404..84e6425a 100644 --- a/scripts/full-recalc.ts +++ b/scripts/full-recalc.ts @@ -20,8 +20,8 @@ const app = initializeApp(firebaseConfig); const db = getFirestore(app); const auth = getAuth(app); -const SUPER_ADMIN_EMAIL = "devpathind.community@gmail.com"; -const SUPER_ADMIN_PASSWORD = "Aditya@2006@#"; +const SUPER_ADMIN_EMAIL = process.env.SUPER_ADMIN_EMAIL; +const SUPER_ADMIN_PASSWORD = process.env.SUPER_ADMIN_PASSWORD; const POINTS = { DAILY_LOGIN: 0, diff --git a/scripts/recalculate-all-points.ts b/scripts/recalculate-all-points.ts index 6627060b..0e9a6c83 100644 --- a/scripts/recalculate-all-points.ts +++ b/scripts/recalculate-all-points.ts @@ -20,8 +20,8 @@ const app = initializeApp(firebaseConfig); const db = getFirestore(app); const auth = getAuth(app); -const SUPER_ADMIN_EMAIL = "devpathind.community@gmail.com"; -const SUPER_ADMIN_PASSWORD = "Aditya@2006@#"; +const SUPER_ADMIN_EMAIL = process.env.SUPER_ADMIN_EMAIL; +const SUPER_ADMIN_PASSWORD = process.env.SUPER_ADMIN_PASSWORD; const POINTS = { DAILY_LOGIN: 0, diff --git a/scripts/seed-admins.ts b/scripts/seed-admins.ts index a77668a7..d1646c3b 100644 --- a/scripts/seed-admins.ts +++ b/scripts/seed-admins.ts @@ -62,7 +62,7 @@ async function seedAdmins() { try { // Login as Super Admin to have write access console.log("Logging in as Super Admin..."); - await signInWithEmailAndPassword(auth, "ap8548328@gmail.com", "Aditya@2006@#"); + await signInWithEmailAndPassword(auth, process.env.SUPER_ADMIN_EMAIL as string, process.env.SUPER_ADMIN_PASSWORD as string); console.log("Logged in successfully."); for (const admin of admins) { diff --git a/src/app/ap/page.tsx b/src/app/ap/page.tsx index d6f50611..9e66fa9b 100644 --- a/src/app/ap/page.tsx +++ b/src/app/ap/page.tsx @@ -9,8 +9,7 @@ import { signInWithEmailAndPassword } from 'firebase/auth'; import { db, auth } from '@/lib/firebase'; import AdminDashboard from '@/components/admin/AdminDashboard'; -const SUPER_ADMIN_EMAIL = "devpathind.community@gmail.com"; -const SUPER_ADMIN_PASSWORD = "Aditya@2006@#"; +const SUPER_ADMIN_EMAIL = process.env.NEXT_PUBLIC_SUPER_ADMIN_EMAIL; export default function SuperAdminLogin() { const { user } = useAuth(); @@ -49,10 +48,12 @@ export default function SuperAdminLogin() { sessionStorage.setItem('admin_session_key', key.trim()); - // 2. Authenticate with Firebase Auth - // This is required for Firestore Rules to allow writes + // 2. Verify Authentication Context + // User must already be authenticated from the main site to perform actions if (!auth.currentUser || auth.currentUser.email !== SUPER_ADMIN_EMAIL) { - await signInWithEmailAndPassword(auth, SUPER_ADMIN_EMAIL, SUPER_ADMIN_PASSWORD); + setError("You must be logged in with the Super Admin account first."); + setLoading(false); + return; } setIsAuthenticated(true); @@ -65,7 +66,20 @@ export default function SuperAdminLogin() { } }; - if (user && user.email !== SUPER_ADMIN_EMAIL) { + if (!user) { + return ( +
You must be logged in with a Super Admin account to access this page.
+ +