-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Camillo Bucciarelli
committed
May 2, 2024
1 parent
9b1e42d
commit 506930e
Showing
3 changed files
with
23 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import { ServiceAccount, cert, initializeApp } from "firebase-admin/app"; | ||
import { | ||
cert, | ||
getApps, | ||
initializeApp, | ||
ServiceAccount, | ||
} from "firebase-admin/app"; | ||
import * as dotenv from "dotenv"; | ||
|
||
// load environment variables | ||
dotenv.config({ path: "../.env" }); | ||
const serviceAccount = JSON.parse( | ||
process.env.PUBLIC_FIREBASE_SERVICE_ACCOUNT || "{}", | ||
); | ||
|
||
// initialize firebase app | ||
export const initialize = () => | ||
initializeApp({ | ||
credential: cert(serviceAccount as ServiceAccount), | ||
}); | ||
const initializeFirebaseApp = () => { | ||
if (getApps().length === 0) { | ||
initializeApp({ | ||
credential: cert(serviceAccount as ServiceAccount), | ||
databaseURL: process.env.FIREBASE_DATABASE_URL, | ||
}); | ||
} | ||
}; | ||
|
||
export const functionsRegion = process.env.PUBLIC_FIREBASE_FUNCTIONS_REGION || ""; | ||
const projectId = serviceAccount.project_id; | ||
|
||
const functionsRegion = process.env.PUBLIC_FIREBASE_FUNCTIONS_REGION || ""; | ||
|
||
export { initializeFirebaseApp, projectId, functionsRegion }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import * as httpApi from "./api/http/api"; | ||
import * as authOnCreate from "./api/auth/on-create"; | ||
import { initialize } from "./config"; | ||
import { initializeFirebaseApp } from "./config"; | ||
|
||
initialize(); | ||
initializeFirebaseApp(); | ||
|
||
exports.http_api = httpApi.default; | ||
exports.onCreateUser = authOnCreate.default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters