1.1.6 • Published 6 months ago

rn-write-firestore v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

🚀 Firetstore Helper for React Native

A utility package for React Native apps which provides an abstract layer around Firebase functionalities, particularly focusing on authentication, and syncing between Firestore and AsyncStorage.

Features

  • 🔒 Firebase Authentication with Google.
  • 💾 Seamless synchronization between Firestore and AsyncStorage.
  • 📖 Comprehensive logging using rn-logging.
  • 📦 Lightweight & minimal setup.

Installation

yarn add rn-write-firestore

Prerequisites

Ensure you have @react-native-firebase/auth, @react-native-firebase/firestore, and @react-native-async-storage/async-storage installed in your React Native project.

Usage

Firebase Configuration Extraction

rn-write-firestore relies on rn-firebase-config which is an embedded mechanism that allows automatic extraction of Firebase configuration from your app's GoogleService-Info.plist. This helps streamline the Firebase setup process, especially if you're looking to avoid hardcoding Firebase configurations or manually importing them.

How does it work?

Under the hood, we use native modules to directly read from the GoogleService-Info.plist and provide a ready-to-use configuration object for Firebase initialization in React Native.

1. Firebase Authentication

To sign in using Firebase with Google credentials:

import { signInFirebase } from 'rn-write-firestore';

const googleCredential = {
  // your google credential here. You can use rn-auth-firebase package to get it.
};

signInFirebase(googleCredential)
  .then(user => {
    console.log("Signed in user:", user);
  })
  .catch(error => {
    console.error("Error during Firebase sign-in:", error);
  });

2. AsyncStorage Operations

To load data from AsyncStorage:

import { loadFromAsyncStorage } from 'rn-write-firestore';

const data = await loadFromAsyncStorage();

To write data to AsyncStorage:

import { writeToAsyncStorage } from 'rn-write-firestore';

const sampleData = {
  key1: 'value1',
  key2: 'value2',
  // ...
};
await writeToAsyncStorage(sampleData);

3. Firestore Operations

To load data from Firestore:

import { loadFromFirebase } from 'rn-write-firestore';

const data = await loadFromFirebase();

To sync AsyncStorage data to Firestore:

import { syncAsyncStorageToFirestore } from 'rn-write-firestore';

await syncAsyncStorageToFirestore();

4. Removing Data from AsyncStorage

To remove a particular data (identified by its storageKey) from AsyncStorage:

import { flushFromAsyncStorage } from 'rn-write-firestore';

await flushFromAsyncStorage();

This function will attempt to locate the data associated with the storageKey in AsyncStorage and then remove it. All actions will be logged using the integrated rn-logging module.

Contribute

Contributions are always welcome! Please read the contribution guidelines first.

License

rn-write-firestore is licensed under MIT.

1.1.1

6 months ago

1.1.0

6 months ago

1.0.39

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.2

6 months ago

1.0.40

6 months ago

1.0.44

6 months ago

1.0.43

6 months ago

1.0.42

6 months ago

1.0.41

6 months ago

1.0.48

6 months ago

1.0.47

6 months ago

1.0.46

6 months ago

1.0.45

6 months ago

1.0.49

6 months ago

1.0.51

6 months ago

1.0.50

6 months ago

1.0.55

6 months ago

1.0.54

6 months ago

1.0.53

6 months ago

1.0.52

6 months ago

1.0.58

6 months ago

1.0.57

6 months ago

1.0.56

6 months ago

1.0.38

7 months ago

1.0.37

7 months ago

1.0.36

7 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.27

7 months ago