Socket
Socket
Sign inDemoInstall

@firebase/app-compat

Package Overview
Dependencies
6
Maintainers
4
Versions
1016
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @firebase/app-compat

The primary entrypoint to the Firebase JS SDK


Version published
Weekly downloads
1.4M
increased by4.77%
Maintainers
4
Install size
2.26 MB
Created
Weekly downloads
 

Package description

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

Readme

Source

@firebase/app-compat

This is the compatibility layer for the Firebase App package, which recreates the v8 API.

This package is not intended for direct usage, and should only be used via the officially supported firebase package.

FAQs

Last updated on 11 Apr 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc