Skip to content

Commit

Permalink
fix: init database instance
Browse files Browse the repository at this point in the history
  • Loading branch information
9renpoto committed Oct 22, 2023
1 parent 8328024 commit 5e80b73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/nestjs-firebase/src/firebase.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface FirebaseAdmin {
auth: firebaseAdmin.auth.Auth;
messaging: firebaseAdmin.messaging.Messaging;
firestore: firebaseAdmin.firestore.Firestore;
database: firebaseAdmin.database.Database;
database?: firebaseAdmin.database.Database;
storage: firebaseAdmin.storage.Storage;
remoteConfig: firebaseAdmin.remoteConfig.RemoteConfig;
}
8 changes: 6 additions & 2 deletions packages/nestjs-firebase/src/util/getFirebaseAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as admin from "firebase-admin";
import { FirebaseAdmin, FirebaseModuleOptions } from "../firebase.interface";

const createInstances = (app: admin.app.App): FirebaseAdmin => ({
const createInstances = (
app: admin.app.App,
initDatabase = false,
): FirebaseAdmin => ({
auth: app.auth(),
messaging: app.messaging(),
firestore: app.firestore(),
database: app.database(),
database: initDatabase ? app.database() : undefined,
storage: app.storage(),
remoteConfig: app.remoteConfig(),
});
Expand All @@ -25,5 +28,6 @@ export const getFirebaseAdmin = (
: undefined,
...appOptions,
}),
!!appOptions.databaseURL,
);
};

0 comments on commit 5e80b73

Please sign in to comment.