Files
Compass/backend/shared/src/firebase-utils.ts
MartinBraquet 90522cb88b Comment log
2025-09-22 00:05:15 +02:00

25 lines
782 B
TypeScript

import {readFileSync} from "fs";
import {ENV_CONFIG} from "common/envs/constants";
export const getServiceAccountCredentials = () => {
let keyPath = ENV_CONFIG.googleApplicationCredentials
// console.log('Using GOOGLE_APPLICATION_CREDENTIALS:', keyPath)
if (!keyPath) {
// throw new Error(
// `Please set the GOOGLE_APPLICATION_CREDENTIALS environment variable to contain the path to your key file.`
// )
return {}
}
if (!keyPath.startsWith('/')) {
// Make relative paths relative to the current file
keyPath = __dirname + '/' + keyPath
// console.log(keyPath)
}
try {
return JSON.parse(readFileSync(keyPath, {encoding: 'utf8'}))
} catch (e) {
throw new Error(`Failed to load service account key from ${keyPath}: ${e}`)
}
}