Skip to content

Commit

Permalink
v1.4.7 (#258)
Browse files Browse the repository at this point in the history
* Firebase Messaging service exposed (`firebase.messaging()`)
* `resetBeforeLogin` config option added (defaults to `true` to keep current behavior) - #254
  • Loading branch information
prescottprue authored Aug 30, 2017
1 parent ac119d9 commit 678fa68
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 49 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,25 @@ Include `reactReduxFirebase` in your store compose function and `firebaseStateR
import { createStore, combineReducers, compose } from 'redux'
import { reactReduxFirebase, firebaseStateReducer } from 'react-redux-firebase'

// Add Firebase to reducers
const rootReducer = combineReducers({
firebase: firebaseStateReducer
})

// Firebase config
const config = {
const firebaseConfig = {
apiKey: '<your-api-key>',
authDomain: '<your-auth-domain>',
databaseURL: '<your-database-url>',
storageBucket: '<your-storage-bucket>'
}

const reduxFirebaseConfig = { userProfile: 'users' }

// Add redux Firebase to compose
const createStoreWithFirebase = compose(
reactReduxFirebase(config, { userProfile: 'users' }),
reactReduxFirebase(firebaseConfig, reduxFirebaseConfig),
)(createStore)

// Add Firebase to reducers
const rootReducer = combineReducers({
firebase: firebaseStateReducer
})

// Create store with reducers and initial state
const initialState = {}
const store = createStoreWithFirebase(rootReducer, initialState)
Expand Down Expand Up @@ -118,7 +119,7 @@ class Todos extends Component {
console.log('Todo Created!')
})
.catch((err) => {
console.log('Error creating todo:', err) // error is also set to authError
console.log('Error creating todo:', err) // error is also set to state.firebase.authError
})
}

Expand Down Expand Up @@ -156,9 +157,9 @@ export default compose(
'todos' // { path: 'todos' } // object notation
]),
connect(
({ firebase } }) => ({ // state.firebase
todos: dataToJS(firebase, 'todos'), // in v2 todos: firebase.data.todos
auth: pathToJS(firebase, 'auth') // in v2 todos: firebase.auth
(state) => ({
todos: dataToJS(state.firebase, 'todos'), // in v2 todos: state.firebase.data.todos
auth: pathToJS(state.firebase, 'auth') // in v2 todos: state.firebase.auth
})
)
)(Todos)
Expand Down Expand Up @@ -280,7 +281,7 @@ The [examples folder](/examples) contains full applications that can be copied/a
* tons of [integrations](#integrations)
* [`profileFactory`](http://react-redux-firebase.com/docs/config) - change format of profile stored on Firebase
* [`getFirebase`](http://react-redux-firebase.com/docs/thunks) - access to firebase instance that fires actions when methods are called
* [access to firebase's `storage`](http://react-redux-firebase.com/docs/storage) method
* [access to firebase's `storage`](http://react-redux-firebase.com/docs/storage) and `messaging` services
* `uniqueSet` method helper for only setting if location doesn't already exist
* Object or String notation for paths (`[{ path: '/todos' }]` equivalent to `['/todos']`)
* Action Types and other Constants are exposed for external usage (such as with `redux-observable`)
Expand All @@ -291,7 +292,7 @@ The [examples folder](/examples) contains full applications that can be copied/a
I have been talking to the author of [redux-react-firebase](https://github.com/tiberiuc/redux-react-firebase) about combining, but we are not sure that the users of both want that at this point. Join us on the [redux-firebase gitter](https://gitter.im/redux-firebase/Lobby) if you haven't already since a ton of this type of discussion goes on there.

#### What about [redux-firebase](https://github.com/colbyr/redux-firebase)?
The author of redux-firebase has agreed to share the npm namespace! Currently the plan is to make a framework agnostic version of the redux core logic of `react-redux-firebase`. Eventually `react-redux-firebase` and potentially other framework libraries can depend on that core (the new `redux-firebase`).
The author of [redux-firebase](https://github.com/colbyr/redux-firebase) has agreed to share the npm namespace! Currently the plan is to take the framework agnostic redux core logic of `react-redux-firebase` and place it into `redux-firebase`. Eventually `react-redux-firebase` and potentially other framework libraries can depend on that core (the new `redux-firebase`).

2. Why use redux if I have Firebase to store state?

Expand Down
2 changes: 2 additions & 0 deletions docs/api/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Middleware that handles configuration (placed in redux's
database logging
- `config.updateProfileOnLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to update
profile when logging in. (default: `false`)
- `config.resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to empty profile
and auth state on login
- `config.enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable
auth redirect handling listener. (default: `true`)
- `config.onAuthStateChanged` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function run when auth state
Expand Down
3 changes: 3 additions & 0 deletions docs/api/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Object containing all action types
- `LOGIN_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/LOGIN_ERROR`
- `NO_VALUE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/NO_VALUE`
- `UNAUTHORIZED_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/UNAUTHORIZED_ERROR`
- `ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/ERROR`
- `UNSET_LISTENER` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/UNSET_LISTENER`
- `AUTHENTICATION_INIT_STARTED` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTHENTICATION_INIT_STARTED`
- `AUTHENTICATION_INIT_FINISHED` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTHENTICATION_INIT_FINISHED`
Expand Down Expand Up @@ -63,6 +64,8 @@ Default configuration options
database logging is enabled.
- `updateProfileOnLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to update
user profile when logging in.
- `resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to reset auth
and profile when logging in (see issue #254 for more details).
- `enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to enable
redirect handling. This must be disabled if environment is not http/https
such as with react-native.
Expand Down
12 changes: 9 additions & 3 deletions docs/api/props-firebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ Firebase ref function

Returns [**database.Reference**](https://firebase.google.com/docs/reference/js/firebase.database.Reference) Firebase database reference

## auth

Firebase auth service instance including all Firebase auth methods

Returns [**Auth**](https://firebase.google.com/docs/reference/js/firebase.auth.Auth)

## database

Firebase database service instance including all Firebase storage methods
Expand All @@ -305,8 +311,8 @@ Firebase storage service instance including all Firebase storage methods

Returns [**Storage**](https://firebase.google.com/docs/reference/js/firebase.storage.Storage) Firebase storage service

## auth
## messaging

Firebase auth service instance including all Firebase auth methods
Firebase messaging service instance including all Firebase messaging methods

Returns [**Auth**](https://firebase.google.com/docs/reference/js/firebase.auth.Auth)
Returns **firebase.messaging** Firebase messaging service
16 changes: 8 additions & 8 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
*None Yet Planned*

#### Features
* Config option for populated items updating when changed - [#69](https://github.com/prescottprue/react-redux-firebase/issues/69)
* `preserveOnLogout` to preserve some data on logout (already supported in v2.0.0)
* Population of ordered data (possibly `populatedOrderToJS`) - [#239](https://github.com/prescottprue/react-redux-firebase/issues/239)
* `childAlias` to store populate result on another parameter - [#126](https://github.com/prescottprue/react-redux-firebase/issues/126)
* `waitForPopulate` option to allow data to be returned before populated data as in becomes available. As of `v1.4.0-rc.2`, populate only sets `isLoaded` to true after all children are loaded, `waitForPopulate` would make this optional - [#121](https://github.com/prescottprue/react-redux-firebase/issues/121)
* Config option for populated items updating when changed - [#69](https://github.com/prescottprue/react-redux-firebase/issues/69)
* Improved support for batching of UI updates as the result of a database "array" loading - [#212](https://github.com/prescottprue/react-redux-firebase/issues/212)
* Expose whole Firebase instance (warning: Using Firebase instance methods will not dispatch actions or update redux state)
* Config option to not remove all data on logout (potential config syntax: `preserveOnLogout: ['todos']`)
* Integration for [`react-native-firebase`](https://github.com/invertase/react-native-firebase) for using Firebase native modules instead of JS library (allowing for instance to be passed in). The syntax may be similar to [`v2.*.*` since it is already supported](http://docs.react-redux-firebase.com/history/v2.0.0/docs/recipes/react-native.html#native-modules).
* Setting that allows for `waitForPopulate` to be turned off (i.e. return populated data as in becomes available). As of `v1.4.0-rc.2`, populate only sets `isLoaded` to true after all children are loaded, `waitForPopulate` would make this optional - [#121](https://github.com/prescottprue/react-redux-firebase/issues/121)


#### Enhancements/Fixes
* Fix `TypeError: Converting circular structure to JSON` (through update of firebase version) - [#230](https://github.com/prescottprue/react-redux-firebase/issues/230)
Expand All @@ -50,6 +50,7 @@
#### Features
* Nested populates [#85](https://github.com/prescottprue/react-redux-firebase/issues/85))
* Support for universal environments (i.e. no `next` function) - [#199](https://github.com/prescottprue/react-redux-firebase/issues/199)
* Option to clear redux data on `firebaseConnect` unmount - [#55](https://github.com/prescottprue/react-redux-firebase/issues/85)

## Upcoming Major Version (`v2.0.0`)

Expand All @@ -72,10 +73,9 @@
* `react-native` index file referenced in `package.json` that makes it no longer necessary to pass `ReactNative` in config
* `AuthRequired` decorator (or decorator factory) that forces auth to exist before rendering component
* Support native modules through [`react-native-firebase`](https://github.com/invertase/react-native-firebase) - [#131](https://github.com/prescottprue/react-redux-firebase/issues/131)
* Detect Non-HTTP environments (such as with SSR) so that `enableRedirectHandling: false` is not required in config
* Track online users and sessions by passing `presence` config option

#### Enhancements/Fixes
* Implement [`firebase-server`](https://github.com/urish/firebase-server) for tests instead of using demo firebase instance
* Support passing Firebase app passed instead of full firebase lib (pass around a smaller object) - [#249](https://github.com/prescottprue/react-redux-firebase/issues/250), [#250](https://github.com/prescottprue/react-redux-firebase/issues/250)

#### Under Consideration
* Allowing `presence` setting to accept a function for dynamically building presence path based on auth
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-firebase",
"version": "1.4.6",
"version": "1.4.7",
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
"browser": "dist/react-redux-firebase.js",
"main": "lib/index.js",
Expand Down
5 changes: 4 additions & 1 deletion src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ export const init = (dispatch, firebase) => {
* @private
*/
export const login = (dispatch, firebase, credentials) => {
dispatchLoginError(dispatch, null)
if (firebase._.config.resetBeforeLogin) {
dispatchLoginError(dispatch, null)
}

let { method, params } = getLoginMethodAndParams(firebase, credentials)

return firebase.auth()[method](...params)
Expand Down
39 changes: 24 additions & 15 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ let firebaseInstance
* database logging
* @property {Boolean} config.updateProfileOnLogin - Whether or not to update
* profile when logging in. (default: `false`)
* @property {Boolean} config.resetBeforeLogin - Whether or not to empty profile
* and auth state on login
* @property {Boolean} config.enableRedirectHandling - Whether or not to enable
* auth redirect handling listener. (default: `true`)
* @property {Function} config.onAuthStateChanged - Function run when auth state
Expand Down Expand Up @@ -431,25 +433,31 @@ export default (fbConfig, otherConfig) => next =>
/**
* @name ref
* @description Firebase ref function
* @return {database.Reference}
* @return {firebase.database.Reference}
* @private
*/
/**
* @name database
* @description Firebase database service instance including all Firebase storage methods
* @return {firebase.database} Firebase database service
* @private
*/
/**
* @name storage
* @description Firebase storage service instance including all Firebase storage methods
* @return {firebase.storage} Firebase storage service
* @private
*/
/**
* @name messaging
* @description Firebase messaging service instance including all Firebase messaging methods
* @return {firebase.messaging} Firebase messaging service
* @private
*/
/**
* @name database
* @description Firebase database service instance including all Firebase storage methods
* @return {Database} Firebase database service
* @private
*/
/**
* @name storage
* @description Firebase storage service instance including all Firebase storage methods
* @return {Storage} Firebase storage service
* @private
*/
/**
* @name auth
* @description Firebase auth service instance including all Firebase auth methods
* @return {Auth}
* @return {firebase.auth} Firebase auth service
* @private
*/
firebase.helpers = {
Expand All @@ -473,7 +481,8 @@ export default (fbConfig, otherConfig) => next =>
verifyPasswordResetCode,
watchEvent,
unWatchEvent,
storage: () => firebase.storage()
storage: () => firebase.storage(),
messaging: () => firebase.messaging()
}

authActions.init(dispatch, instance)
Expand Down
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const actionsPrefix = '@@reactReduxFirebase'
* @property {String} LOGIN_ERROR - `@@reactReduxFirebase/LOGIN_ERROR`
* @property {String} NO_VALUE - `@@reactReduxFirebase/NO_VALUE`
* @property {String} UNAUTHORIZED_ERROR - `@@reactReduxFirebase/UNAUTHORIZED_ERROR`
* @property {String} ERROR - `@@reactReduxFirebase/ERROR`
* @property {String} UNSET_LISTENER - `@@reactReduxFirebase/UNSET_LISTENER`
* @property {String} AUTHENTICATION_INIT_STARTED - `@@reactReduxFirebase/AUTHENTICATION_INIT_STARTED`
* @property {String} AUTHENTICATION_INIT_FINISHED - `@@reactReduxFirebase/AUTHENTICATION_INIT_FINISHED`
Expand Down Expand Up @@ -65,6 +66,8 @@ export const actionTypes = {
* database logging is enabled.
* @property {Boolean} updateProfileOnLogin - `true` Whether or not to update
* user profile when logging in.
* @property {Boolean} resetBeforeLogin - `true` Whether or not to reset auth
* and profile when logging in (see issue #254 for more details).
* @property {Boolean} enableRedirectHandling - `true` Whether or not to enable
* redirect handling. This must be disabled if environment is not http/https
* such as with react-native.
Expand All @@ -84,6 +87,7 @@ export const actionTypes = {
export const defaultConfig = {
userProfile: null,
enableLogging: false,
resetBeforeLogin: true,
updateProfileOnLogin: true,
enableRedirectHandling: true,
autoPopulateProfile: true,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/actions/auth.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global describe expect it beforeEach */
import {
dispatchLoginError,
dispatchUnauthorizedError,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/library.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global describe expect it */
import src from '../../src'

describe('module', () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/utils/auth.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global firebase describe expect it */
import {
createAuthProvider,
getLoginMethodAndParams
Expand Down
1 change: 0 additions & 1 deletion tests/unit/utils/events.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global describe expect it beforeEach */
import { getEventsFromInput } from '../../../src/utils/events'

describe('Utils: Events', () => {
Expand Down
1 change: 0 additions & 1 deletion tests/unit/utils/populate.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global describe expect it beforeEach */
import {
getPopulateObj,
getPopulates,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/utils/query.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global describe expect it beforeEach */
import {
getWatchPath,
setWatcher,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/utils/storage.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global describe expect it */
import { deleteFile } from '../../../src/utils/storage'
const fakeFirebase = {
_: {
Expand Down

0 comments on commit 678fa68

Please sign in to comment.