mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 01:51:37 -04:00
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import {IS_FIREBASE_EMULATOR} from 'common/envs/constants'
|
|
import {IS_LOCAL} from 'common/hosting/constants'
|
|
import {debug} from 'common/logger'
|
|
import * as admin from 'firebase-admin'
|
|
import {getServiceAccountCredentials} from 'shared/firebase-utils'
|
|
|
|
export const initAdmin = () => {
|
|
if (IS_LOCAL && IS_FIREBASE_EMULATOR) {
|
|
// console.log("Using Firebase Emulator Suite.")
|
|
return admin.initializeApp({
|
|
projectId: 'compass-57c3c',
|
|
storageBucket: 'compass-130ba-public',
|
|
})
|
|
}
|
|
|
|
if (IS_LOCAL) {
|
|
try {
|
|
const serviceAccount = getServiceAccountCredentials()
|
|
|
|
if (!serviceAccount.project_id) {
|
|
debug(`GOOGLE_APPLICATION_CREDENTIALS not set, skipping admin firebase init.`)
|
|
return
|
|
}
|
|
debug(`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)
|
|
}
|
|
}
|
|
|
|
debug(`Initializing connection to default Firebase...`)
|
|
return admin.initializeApp()
|
|
}
|