firebase-sagas
A redux-saga integration for firebase (auth, database):
- Authentication and realtime database support
- Listen for value and child events (
value
,child_added
,child_removed
,child_changed
,child_moved
) - Snapshots as array support
- Sorting and filtering data (
orderByChild
,orderByKey
,orderByValue
,orderByPriority
,limitToLast
,limitToFirst
,startAt
,endAt
,equalTo
)
Try out the example app
Install
npm install firebase-sagas --save
Getting started
import createFirebaseSagas from 'firebase-sagas';
const config = {
apiKey: 'YOUR_API_KEY',
authDomain: 'YOUR_AUTH_DOMAIN',
databaseURL: 'YOUR_DATABASE_URL',
projectId: 'YOUR_PROJECT_ID',
storageBucket: 'YOUR_STORAGE_BUCKET',
messagingSenderId: 'YOUR_MESSAGING_SENDER_ID'
};
const firebaseSagas = createFirebaseSagas(config);
...
function* fetchDataSaga(action) {
try {
const { query } = action.payload;
const data = yield call(firebaseSagas.database.once, '/data', 'value', { query, asArray: true });
yield put(fetchDataSuccess(data));
}
catch(error) {
yield put(fetchDataFailure(error));
}
}
...
API
Modules
- constants
-
Constants.
- auth
-
A module for firebaseSagas.auth
- database
-
A module for firebaseSagas.database
Classes
- FirebaseSagas
-
FirebaseSagas
- Query
-
Query
Functions
-
createAuthSaga(FirebaseSagas, options) ⇒
generator
-
Creates a AuthSaga
-
createFirebaseSagas(config) ⇒
FirebaseSagas
-
Creates a FirebaseSagas-Instance
-
createQuery() ⇒
Query
-
Creates a new Query
constants
Constants.
auth
A module for firebaseSagas.auth
-
auth
-
~createUserWithEmailAndPassword(email, password) ⇒
firebase.User
-
~signInWithEmailAndPassword(email, password) ⇒
firebase.User
-
~signInAnonymously() ⇒
firebase.User
-
~signInWithCustomToken(token) ⇒
firebase.User
-
~signInWithGoogle(scopes, customParameters) ⇒
firebase.User
-
~signInWithFacebook(scopes, customParameters) ⇒
firebase.User
-
~signInWithTwitter(scopes, customParameters) ⇒
firebase.User
-
~signInWithGithub(scopes, customParameters) ⇒
firebase.User
- ~signOut()
- ~syncUser(actionCreator)
-
~createOnAuthStateChangedChannel() ⇒
eventChannel
-
~currentUser() ⇒
firebase.User
-
~createUserWithEmailAndPassword(email, password) ⇒
firebase.User
auth~createUserWithEmailAndPassword(email, password) ⇒ Creates a new user account associated with the specified email address and password.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type |
---|---|
string |
|
password | string |
firebase.User
auth~signInWithEmailAndPassword(email, password) ⇒ Signs in using an email and password.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type |
---|---|
string |
|
password | string |
firebase.User
auth~signInAnonymously() ⇒ Signs in as an anonymous user.
Kind: inner method of auth
Returns: firebase.User
- user
firebase.User
auth~signInWithCustomToken(token) ⇒ Signs in using a custom token.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type | Description |
---|---|---|
token | string |
The custom token to sign in with. |
firebase.User
auth~signInWithGoogle(scopes, customParameters) ⇒ Signs in using GoogleAuthProvider.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type | Description |
---|---|---|
scopes | array |
Google OAuth scopes |
customParameters | object |
The custom OAuth parameters to pass in the OAuth request |
firebase.User
auth~signInWithFacebook(scopes, customParameters) ⇒ Signs in using FacebookAuthProvider.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type | Description |
---|---|---|
scopes | array |
Facebook OAuth scopes |
customParameters | object |
The custom OAuth parameters to pass in the OAuth request |
firebase.User
auth~signInWithTwitter(scopes, customParameters) ⇒ Signs in using TwitterAuthProvider.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type | Description |
---|---|---|
scopes | array |
Twitter OAuth scopes |
customParameters | object |
The custom OAuth parameters to pass in the OAuth request |
firebase.User
auth~signInWithGithub(scopes, customParameters) ⇒ Signs in using GithubAuthProvider.
Kind: inner method of auth
Returns: firebase.User
- user
Param | Type | Description |
---|---|---|
scopes | array |
Github OAuth scopes |
customParameters | object |
The custom OAuth parameters to pass in the OAuth request |
auth~signOut()
Signs out the current user.
Kind: inner method of auth
auth~syncUser(actionCreator)
Kind: inner method of auth
Param | Type |
---|---|
actionCreator | function |
eventChannel
auth~createOnAuthStateChangedChannel() ⇒ Creates channel that will subscribe to changes to the user's sign-in state.
Kind: inner method of auth
Returns: eventChannel
- onAuthStateChangedChannel
firebase.User
auth~currentUser() ⇒ Returns the currently signed-in user (or null).
Kind: inner method of auth
Returns: firebase.User
- user
database
A module for firebaseSagas.database
*
| any
database~once(path, eventType, options) ⇒ Retrieve data from database just once without subscribing or listening for data changes.
Kind: inner method of database
Param | Type |
---|---|
path | string |
eventType | string |
options | object |
*
| any
database~push(path, value) ⇒ Generates a new child location using a unique key and returns its Reference
Kind: inner method of database
Param | Type |
---|---|
path | string |
value |
database~update(path, values)
Writes multiple values to the Database at once.
Kind: inner method of database
Param | Type |
---|---|
path | string |
values |
database~set(path, value)
Writes data to this Database location.
Kind: inner method of database
Param | Type |
---|---|
path | string |
value |
database~remove(path)
Removes the data at this Database location.
Kind: inner method of database
Param | Type |
---|---|
path | string |
database~on(path, eventType, actionCreator, options)
Kind: inner method of database
Param | Type |
---|---|
path | string |
eventType | string |
actionCreator | function |
options | object |
eventChannel
database~createOnEventChannel(path, eventType) ⇒ Kind: inner method of database
Returns: eventChannel
- onEventChannel
Param | Type |
---|---|
path | string |
eventType | string |
FirebaseSagas
FirebaseSagas
Kind: global class
firebaseSagas.database
See module database
Kind: instance property of FirebaseSagas
See: database
firebaseSagas.auth
See module auth
Kind: instance property of FirebaseSagas
See: auth
Query
Query
Kind: global class
query.equalTo(value, key)
Creates a Query that includes children that match the specified value.
Kind: instance method of Query
Param | Type | Description |
---|---|---|
value | The value to match for. The argument type depends on which orderBy*() function was used in this query. Specify a value that matches the orderBy*() type. When used in combination with orderByKey(), the value must be a string. | |
key | optional |
The child key to start at, among the children with the previously specified priority. This argument is only allowed if ordering by child, value, or priority. |
query.startAt(value, key)
Creates a Query with the specified starting point.
Kind: instance method of Query
Param | Type | Description |
---|---|---|
value | The value to start at. The argument type depends on which orderBy*() function was used in this query. Specify a value that matches the orderBy*() type. When used in combination with orderByKey(), the value must be a string. | |
key | optional |
The child key to start at. This argument is only allowed if ordering by child, value, or priority. |
query.endAt(value, key)
Creates a Query with the specified ending point.
Kind: instance method of Query
Param | Type | Description |
---|---|---|
value | The value to end at. The argument type depends on which orderBy*() function was used in this query. Specify a value that matches the orderBy*() type. When used in combination with orderByKey(), the value must be a string. | |
key | optional |
query.limitToLast(limit)
Generates a new Query object limited to the last specific number of children.
Kind: instance method of Query
Param | Description |
---|---|
limit | The maximum number of nodes to include in this query. |
query.limitToFirst(limit)
Generates a new Query limited to the first specific number of children.
Kind: instance method of Query
Param | Description |
---|---|
limit | The maximum number of nodes to include in this query. |
query.orderByValue()
Generates a new Query object ordered by value.
Kind: instance method of Query
query.orderByPriority()
Generates a new Query object ordered by priority.
Kind: instance method of Query
query.orderByChild(path)
Generates a new Query object ordered by the specified child key.
Kind: instance method of Query
Param |
---|
path |
query.orderByKey()
Generates a new Query object ordered by key.
Kind: instance method of Query
query.reset()
Resets the query
Kind: instance method of Query
query.toJSON()
Return the query as JSON-String
Kind: instance method of Query
generator
createAuthSaga(FirebaseSagas, options) ⇒ Creates a AuthSaga
Kind: global function
Returns: generator
- authSaga
Param | Type |
---|---|
FirebaseSagas | FirebaseSagas |
options | object |
Example
import { createAuthSaga } from 'firebase-sagas';
...
const authSaga = createAuthSaga(firebaseSagas, {
signInMethods: [
{ type: 'signInWithEmailAndPassword' },
{ type: 'signInWithGoogle' },
],
onSignInSuccess: function* onSignInSuccess() {
yield put(push('/Todo'));
},
onSignOutSuccess: function* onSignOutSuccess() {
yield put(push('/'));
},
});
FirebaseSagas
createFirebaseSagas(config) ⇒ Creates a FirebaseSagas-Instance
Kind: global function
Returns: FirebaseSagas
- firebaseSagas
Param | Type | Description |
---|---|---|
config | object |
FireBase config |
Example
import createFirebaseSagas from 'firebase-sagas':
const config = {
apiKey: 'YOUR_API_KEY',
authDomain: 'YOUR_AUTH_DOMAIN',
databaseURL: 'YOUR_DATABASE_URL',
projectId: 'YOUR_PROJECT_ID',
storageBucket: 'YOUR_STORAGE_BUCKET',
messagingSenderId: 'YOUR_MESSAGING_SENDER_ID'
};
const firebaseSagas = createFirebaseSagas(config);
Query
createQuery() ⇒ Creates a new Query
Kind: global function
Returns: Query
- query
Example
import { createQuery } from 'firebase-sagas';
const query = createQuery().startAt(10).endAt(15).orderByValue();