Skip to content

Commit

Permalink
fix off by one
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Mar 11, 2024
1 parent 75be265 commit f3e5f39
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions server/src/business-layer/security/Firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ import {
} from "data-layer/adapters/EmulatorConfig"
import * as _admin from "firebase-admin"

const IS_JEST = process.env.JEST_WORKER_ID === undefined
const IS_JEST = process.env.JEST_WORKER_ID !== undefined

const keysEnvVar = process.env.GOOGLE_SERVICE_ACCOUNT_JSON
let keys

if (!keysEnvVar && IS_JEST) {
if (!keysEnvVar && !IS_JEST) {
throw new Error("The service account environment variable was not found!")
}

if (!IS_JEST) {
keys = JSON.parse(keysEnvVar)
}
const keys = JSON.parse(keysEnvVar ?? "{}")

if (process.env.DEV || IS_JEST) {
process.env.FIRESTORE_EMULATOR_HOST = `${EMULATOR_HOST}:${EMULATOR_FIRESTORE_PORT}`
}

const firebase = _admin.initializeApp({
credential: _admin.credential.cert(keys)
})
const firebase = _admin.initializeApp(
Object.keys(keys).length > 0
? {
credential: _admin.credential.cert(keys)
}
: {}
)

export const admin = _admin

Expand Down

0 comments on commit f3e5f39

Please sign in to comment.