-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-firebase-admin.js
More file actions
56 lines (46 loc) · 1.97 KB
/
test-firebase-admin.js
File metadata and controls
56 lines (46 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require('dotenv').config({ path: '.env' });
async function testFirebaseAdmin() {
console.log('🔌 Testing Firebase Admin initialization...');
try {
// Test if environment variable is loaded
console.log('📋 Environment check:');
console.log(' FIREBASE_ADMIN_SDK_KEY exists:', !!process.env.FIREBASE_ADMIN_SDK_KEY);
console.log(' FIREBASE_ADMIN_SDK_KEY length:', process.env.FIREBASE_ADMIN_SDK_KEY ? process.env.FIREBASE_ADMIN_SDK_KEY.length : 0);
// Try to parse the service account
let serviceAccount;
try {
serviceAccount = JSON.parse(process.env.FIREBASE_ADMIN_SDK_KEY);
console.log('✅ Service account parsed successfully');
console.log(' Project ID:', serviceAccount.project_id);
console.log(' Client Email:', serviceAccount.client_email);
} catch (parseError) {
console.error('❌ Failed to parse service account:', parseError.message);
return;
}
// Test Firebase Admin initialization
console.log('\n🚀 Testing Firebase Admin initialization...');
const admin = require('firebase-admin');
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
projectId: serviceAccount.project_id,
});
console.log('✅ Firebase Admin app initialized');
} else {
console.log('✅ Firebase Admin app already exists');
}
// Test auth functionality
console.log('\n🔐 Testing Admin Auth...');
const adminAuth = admin.auth();
console.log('✅ Admin Auth initialized');
// Test firestore functionality
console.log('\n📚 Testing Admin Firestore...');
const adminFirestore = admin.firestore();
console.log('✅ Admin Firestore initialized');
console.log('\n🎉 All Firebase Admin tests passed!');
} catch (error) {
console.error('❌ Firebase Admin test failed:', error.message);
console.error('Stack trace:', error.stack);
}
}
testFirebaseAdmin();