mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-26 03:47:01 -05:00
28 lines
836 B
TypeScript
28 lines
836 B
TypeScript
import * as admin from 'firebase-admin'
|
|
|
|
import { getServiceAccountCredentials } from 'common/secrets'
|
|
|
|
export const getLocalEnv = () => {
|
|
return (process.env.ENV?.toUpperCase() ?? 'STAGING') as 'PROD' | 'DEV'
|
|
}
|
|
|
|
// Locally initialize Firebase Admin.
|
|
export const initAdmin = () => {
|
|
try {
|
|
const env = getLocalEnv()
|
|
const serviceAccount = getServiceAccountCredentials(env)
|
|
console.log(
|
|
`Initializing connection to ${serviceAccount.project_id} Firebase...`
|
|
)
|
|
return admin.initializeApp({
|
|
projectId: serviceAccount.project_id,
|
|
credential: admin.credential.cert(serviceAccount),
|
|
storageBucket: `${serviceAccount.project_id}.appspot.com`,
|
|
})
|
|
} catch (err) {
|
|
console.error(err)
|
|
console.log(`Initializing connection to default Firebase...`)
|
|
return admin.initializeApp()
|
|
}
|
|
}
|