redux-saga-firebase
A redux-saga integration for firebase.
- Try out the example app and browse its code.
- Browse the docs at https://n6g7.github.io/redux-saga-firebase/.
Quick start
Install with:
yarn add redux-saga-firebase
Initialize a firebase app and instanciate redux-saga-firebase:
import firebase from 'firebase';
import '@firebase/firestore'; // 👈 If you're using firestore
import ReduxSagaFirebase from 'redux-saga-firebase';
const myFirebaseApp = firebase.initializeApp({
apiKey: "qosjdqsdkqpdqldkqdkfojqjpfk",
authDomain: "my-app.firebaseapp.com",
databaseURL: "https://my-app.firebaseio.com",
});
const reduxSagaFirebase = new ReduxSagaFirebase(myFirebaseApp)
// Or, to use firestore:
const reduxSagaFirebase = new ReduxSagaFirebase(myFirebaseApp, firebase.firestore())
You can now use reduxSagaFirebase
methods in your sagas:
const authProvider = new firebase.auth.GoogleAuthProvider();
function* loginSaga() {
try {
const data = yield call(reduxSagaFirebase.auth.signInWithPopup, authProvider);
yield put(loginSuccess(data));
}
catch(error) {
yield put(loginFailure(error));
}
}
export default function* rootSaga() {
yield [
takeEvery(types.LOGIN.REQUEST, loginSaga)
];
}
Make sure your client provides a implementation of fetch
, either natively or via a polyfill (whatwg-fetch
is a pretty good one).
API
Index
Authentication
*auth.applyActionCode(code)
auth.channel()
*auth.confirmPasswordReset(code, newPassword)
*auth.createUserWithEmailAndPassword(email, password)
*auth.sendEmailVerification(actionCodeSettings)
*auth.sendPasswordResetEmail(email, actionCodeSettings)
*auth.signInAndRetrieveDataWithCredential(credential)
*auth.signInAnonymously()
*auth.signInWithCredential(credential)
*auth.signInWithCustomToken(token)
*auth.signInWithEmailAndPassword(email, password)
*auth.signInWithPhoneNumber(phoneNumber, applicationVerifier)
*auth.signInWithPopup(authProvider)
*auth.signInWithRedirect(authProvider)
*auth.signOut()
*auth.updatePassword(password)
Database
*database.read(path)
*database.create(path, data)
*database.update(path, data)
*database.patch(path, data)
*database.delete(path)
database.channel(path, event)
*database.sync(path, options)
Firestore
*firestore.addDocument(collectionRef, data)
firestore.channel(pathOrRef, type)
*firestore.deleteDocument(documentRef)
*firestore.getCollection(collectionRef)
*firestore.getDocument(docRef)
*firestore.setDocument(docRef, data, options)
*firestore.syncCollection(pathOrRef, options)
*firestore.syncDocument(pathOrRef, options)
*firestore.updateDocument(docRef, ...args)
Functions
Messaging
messaging.channel()
*messaging.syncMessages(options)
*messaging.syncToken(options)
messaging.tokenRefreshChannel()
Storage