Skip to main content

Overview

The Firebase configuration module initializes Firebase services and exports authentication and Firestore database instances used throughout the application. Source: public/js/firebase.js

Firebase SDK Imports

StockPro uses Firebase JavaScript SDK v10.12.2 from CDN:
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";
initializeApp
function
Initializes a Firebase app instance with the provided configuration
getAuth
function
Returns the Firebase Authentication service instance
getFirestore
function
Returns the Cloud Firestore service instance

Firebase Configuration Object

The application uses the following Firebase project configuration:
const firebaseConfig = {
    apiKey: "AIzaSyCK79FXbS3tNPL8V6C03HOMyrr8-rp6YO4",
    authDomain: "autopartes-hessman-68283.firebaseapp.com",
    projectId: "autopartes-hessman-68283",
    storageBucket: "autopartes-hessman-68283.firebasestorage.app",
    messagingSenderId: "854961822123",
    appId: "1:854961822123:web:75d5b5d3d3e567761e9aee",
    measurementId: "G-ENNB0G1JME"
};

Configuration Parameters

apiKey
string
required
Firebase API key for client authentication
authDomain
string
required
Domain for Firebase Authentication redirects
projectId
string
required
Unique identifier for the Firebase project
storageBucket
string
Cloud Storage bucket URL
messagingSenderId
string
Sender ID for Firebase Cloud Messaging
appId
string
required
Unique application identifier
measurementId
string
Google Analytics measurement ID

Service Initialization

Firebase services are initialized and exported as singleton instances:
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);

export { auth, db };

Exported Services

auth
Auth
Firebase Authentication service instance. Use this for all authentication operations including sign-in, sign-out, and auth state monitoring.
db
Firestore
Cloud Firestore database instance. Use this for all database operations including reading and writing documents.

Usage in Other Modules

Import the auth and db services in any JavaScript module:
import { auth, db } from "./firebase.js";

// Use auth for authentication
// Use db for Firestore operations

Complete Source Code

public/js/firebase.js
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js";

// Your web app's Firebase configuration
const firebaseConfig = {
    apiKey: "AIzaSyCK79FXbS3tNPL8V6C03HOMyrr8-rp6YO4",
    authDomain: "autopartes-hessman-68283.firebaseapp.com",
    projectId: "autopartes-hessman-68283",
    storageBucket: "autopartes-hessman-68283.firebasestorage.app",
    messagingSenderId: "854961822123",
    appId: "1:854961822123:web:75d5b5d3d3e567761e9aee",
    measurementId: "G-ENNB0G1JME"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);

export { auth, db };

Build docs developers (and LLMs) love