Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backend/src/config/firebaseAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ const getFirestore = () => {
return adminClient.firestore();
};

// Helper function to initialize and get the Firebase Auth Admin module
const getAuth = () => {
const adminClient = initFirebaseAdmin();
return adminClient.auth();
};

// Exporting the modules so they can be securely used across backend routes
module.exports = {
getFirestore,
};
getAuth,
};
45 changes: 18 additions & 27 deletions scripts/verify-admin.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
// Import the central admin utilities we updated in Step 1
// Adjust this path relative to where this verification script file lives
const { getFirestore } = require("./path-to-your-init-file");
const path = require('path');

import { initializeApp } from 'firebase/app';
import { getFirestore, doc, getDoc } from 'firebase/firestore';

dotenv.config({ path: '.env.local' });

import * as dotenv from 'dotenv';
dotenv.config({ path: '.env.local' });

const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
// Configure dotenv to read from the project root .env.local
require('dotenv').config({ path: path.join(__dirname, '..', '.env.local') });

async function verifyAdmin() {
try {
const email = 'ap8548328@gmail.com';
console.log(`Fetching admin: ${email}`);
const docRef = doc(db, 'admins', email);
const docSnap = await getDoc(docRef);
console.log(`Fetching admin via Admin SDK: ${email}`);

// Use the safe backend firestore instance
const db = getFirestore();

// Admin SDK uses .collection().doc().get() instead of the client getDoc() function
const docRef = db.collection('admins').doc(email);
const docSnap = await docRef.get();

if (docSnap.exists()) {
if (docSnap.exists) {
console.log('Admin Data:', JSON.stringify(docSnap.data(), null, 2));
} else {
console.log('No such document!');
console.log('No such document found in admins collection!');
}
} catch (error) {
console.error('Error fetching admin:', error);
console.error('Error fetching admin securely:', error);
}
}

verifyAdmin();
verifyAdmin();