-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate-env.js
More file actions
42 lines (33 loc) · 1.17 KB
/
validate-env.js
File metadata and controls
42 lines (33 loc) · 1.17 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
const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');
const envConfig = dotenv.parse(fs.readFileSync('.env.local'));
const key = envConfig.FIREBASE_SERVICE_ACCOUNT_KEY;
if (!key) {
console.error("❌ FIREBASE_SERVICE_ACCOUNT_KEY is missing in .env.local");
process.exit(1);
}
try {
let jsonString = key;
// START: Mirroring admin.ts logic
if (jsonString.startsWith("'") && jsonString.endsWith("'")) {
jsonString = jsonString.slice(1, -1);
}
// END: Mirroring admin.ts logic
const json = JSON.parse(jsonString);
// START: Mirroring admin.ts logic
if (json.private_key) {
json.private_key = json.private_key.replace(/\\n/g, '\n');
}
// END: Mirroring admin.ts logic
if (!json.project_id || !json.private_key) {
console.error("❌ JSON is missing project_id or private_key");
process.exit(1);
}
console.log("✅ Service Account Key JSON is valid!");
console.log("Project ID:", json.project_id);
} catch (e) {
console.error("❌ Failed to parse JSON:", e.message);
console.error("Raw content (first 50 chars):", key.substring(0, 50));
process.exit(1);
}