Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@firebase/app-compat

Package Overview
Dependencies
Maintainers
4
Versions
1205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/app-compat

The primary entrypoint to the Firebase JS SDK

  • 0.2.41-20240916151535
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9M
increased by7.44%
Maintainers
4
Weekly downloads
 
Created

What is @firebase/app-compat?

The @firebase/app-compat package is a compatibility layer for Firebase that allows developers to use the Firebase SDK with an API surface that is compatible with the older 'firebase' npm package (version 8 and below). It enables developers to upgrade to the modular Firebase SDK (version 9 and above) without having to refactor all of their existing code that was written using the older syntax.

What are @firebase/app-compat's main functionalities?

Initialization

This code initializes a Firebase app instance using the older, non-modular syntax. It is used to set up the Firebase context for further interactions with Firebase services.

const firebase = require('@firebase/app-compat');
const app = firebase.initializeApp({ apiKey: 'API_KEY', authDomain: 'PROJECT_ID.firebaseapp.com', projectId: 'PROJECT_ID' });

Authentication

This code demonstrates how to sign in a user with an email and password using Firebase Authentication. It uses the older syntax for ease of use with existing codebases.

const firebase = require('@firebase/app-compat');
const auth = firebase.auth();
auth.signInWithEmailAndPassword('user@example.com', 'password').then((userCredential) => {
  // Handle successful authentication
}).catch((error) => {
  // Handle errors
});

Realtime Database

This code snippet shows how to listen for real-time updates from the Firebase Realtime Database at a specific path. It uses the traditional Firebase syntax.

const firebase = require('@firebase/app-compat');
const database = firebase.database();
database.ref('path/to/data').on('value', (snapshot) => {
  const data = snapshot.val();
  // Use the data
});

Firestore

This code sample demonstrates how to retrieve a document from a Firestore collection using the older Firebase syntax. It is useful for developers who have existing Firestore interactions written in the non-modular style.

const firebase = require('@firebase/app-compat');
const firestore = firebase.firestore();
firestore.collection('users').doc('user_id').get().then((doc) => {
  if (doc.exists) {
    const user = doc.data();
    // Use the user data
  }
}).catch((error) => {
  // Handle errors
});

Other packages similar to @firebase/app-compat

FAQs

Package last updated on 16 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc