
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
@snowdrive/firebase-handler
Advanced tools
A wrapper for Firestore, Realtime Database, and Storage services provided by the firebase-admin library. It's designed to handle singleton instances of those Firebase services, simplifying the access to them.
npm install @snowdrive/firebase-handler
yarn add @snowdrive/firebase-handler
pnpm add @snowdrive/firebase-handler
Make sure to initialize the library with the required dependencies.
Firebase app credentials can be configurated in three ways:
applicationDefault function from the firebase-admin library.Note: By default, if you don't provide any credentials, the library will try to connect to the services using the applicationDefault option.
const credentialConfig = {
serviceAccount: {
projectId: "<PROJECT_ID>",
clientEmail: "foo@<PROJECT_ID>.iam.gserviceaccount.com",
privateKey: "-----BEGIN PRIVATE KEY-----<KEY>-----END PRIVATE KEY-----\n"
},
// or
refreshToken: "<REFRESH_TOKEN>"
}
const config = {
firebase: {
credential: credentialConfig
}
}
You can also provide the path to a JSON file containing the service account or the refresh token configuration.To read more about the Firebase App initialization, check the official documentation.
Note: If you try to use both configuration properties, the service account object will be prioritized.
To configurate the Realtime Database and Storage Bucket, you can use the databaseURL and storageBucket properties respectively.
const config = {
firebase: {
credential: { /* Previous configuration */ },
databaseURL: 'https://<DATABASE_NAME>.firebaseio.com',
storageBucket: '<PROJECT_ID>.appspot.com',
}
}
Note: Both are optional, but you won't be able to use the services that require them.
You can also provide the Firestore settings, which are optional, including the top-level configuration property. Also, you can use the "handlers" configuration to use our recommended settings for the services.
const config = {
firestore: {
// All compatible firestore settings provided by the firebase-admin library.
},
handlers: {
useFirestoreRecommendedSettings: true, // Enable recommended settings for Firestore.
}
}
The Firestore recommended settings enable ignoreUndefinedProperties property.
Set up your logger (here's a basic example):
const logger = {
info: (message, data) => { console.log(message, data) },
error: (message, data) => { console.error(message, data) }
}
Using the provided configurations:
import * as admin from 'firebase-admin'
import { FirebaseHandler } from '@snowdrive/firebase-handler'
const dependencies = {
admin: admin,
config: config,
logger: logger
}
const firebaseHandler = new FirebaseHandler(dependencies)
const firestore = firebaseHandler.getFirestoreInstance()
const realtimeDb = firebaseHandler.getRealtimeInstance()
Note: Ensure your configuration includes databaseURL.
const storage = firebaseHandler.getStorageInstance()
Note: Ensure your configuration includes storageBucket.
To disconnect from all services:
firebaseHandler.disconnect()
Explore the source code, report issues, or contribute to the development of this project at our GitHub Repository. Your feedback and contributions are highly appreciated!
This project is licensed under the GPL-3.0-or-later. See the LICENSE file in the repository for details.
FAQs
Firestore, Realtime Database and Storage wrapper
We found that @snowdrive/firebase-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.