Skip to content

Commit 678fa68

Browse files
authored
v1.4.7 (#258)
* Firebase Messaging service exposed (`firebase.messaging()`) * `resetBeforeLogin` config option added (defaults to `true` to keep current behavior) - #254
1 parent ac119d9 commit 678fa68

File tree

16 files changed

+70
-49
lines changed

16 files changed

+70
-49
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,25 @@ Include `reactReduxFirebase` in your store compose function and `firebaseStateR
6464
import { createStore, combineReducers, compose } from 'redux'
6565
import { reactReduxFirebase, firebaseStateReducer } from 'react-redux-firebase'
6666

67-
// Add Firebase to reducers
68-
const rootReducer = combineReducers({
69-
firebase: firebaseStateReducer
70-
})
71-
72-
// Firebase config
73-
const config = {
67+
const firebaseConfig = {
7468
apiKey: '<your-api-key>',
7569
authDomain: '<your-auth-domain>',
7670
databaseURL: '<your-database-url>',
7771
storageBucket: '<your-storage-bucket>'
7872
}
7973

74+
const reduxFirebaseConfig = { userProfile: 'users' }
75+
8076
// Add redux Firebase to compose
8177
const createStoreWithFirebase = compose(
82-
reactReduxFirebase(config, { userProfile: 'users' }),
78+
reactReduxFirebase(firebaseConfig, reduxFirebaseConfig),
8379
)(createStore)
8480

81+
// Add Firebase to reducers
82+
const rootReducer = combineReducers({
83+
firebase: firebaseStateReducer
84+
})
85+
8586
// Create store with reducers and initial state
8687
const initialState = {}
8788
const store = createStoreWithFirebase(rootReducer, initialState)
@@ -118,7 +119,7 @@ class Todos extends Component {
118119
console.log('Todo Created!')
119120
})
120121
.catch((err) => {
121-
console.log('Error creating todo:', err) // error is also set to authError
122+
console.log('Error creating todo:', err) // error is also set to state.firebase.authError
122123
})
123124
}
124125

@@ -156,9 +157,9 @@ export default compose(
156157
'todos' // { path: 'todos' } // object notation
157158
]),
158159
connect(
159-
({ firebase } }) => ({ // state.firebase
160-
todos: dataToJS(firebase, 'todos'), // in v2 todos: firebase.data.todos
161-
auth: pathToJS(firebase, 'auth') // in v2 todos: firebase.auth
160+
(state) => ({
161+
todos: dataToJS(state.firebase, 'todos'), // in v2 todos: state.firebase.data.todos
162+
auth: pathToJS(state.firebase, 'auth') // in v2 todos: state.firebase.auth
162163
})
163164
)
164165
)(Todos)
@@ -280,7 +281,7 @@ The [examples folder](/examples) contains full applications that can be copied/a
280281
* tons of [integrations](#integrations)
281282
* [`profileFactory`](http://react-redux-firebase.com/docs/config) - change format of profile stored on Firebase
282283
* [`getFirebase`](http://react-redux-firebase.com/docs/thunks) - access to firebase instance that fires actions when methods are called
283-
* [access to firebase's `storage`](http://react-redux-firebase.com/docs/storage) method
284+
* [access to firebase's `storage`](http://react-redux-firebase.com/docs/storage) and `messaging` services
284285
* `uniqueSet` method helper for only setting if location doesn't already exist
285286
* Object or String notation for paths (`[{ path: '/todos' }]` equivalent to `['/todos']`)
286287
* Action Types and other Constants are exposed for external usage (such as with `redux-observable`)
@@ -291,7 +292,7 @@ The [examples folder](/examples) contains full applications that can be copied/a
291292
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.
292293

293294
#### What about [redux-firebase](https://github.com/colbyr/redux-firebase)?
294-
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`).
295+
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`).
295296

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

docs/api/compose.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Middleware that handles configuration (placed in redux's
3030
database logging
3131
- `config.updateProfileOnLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to update
3232
profile when logging in. (default: `false`)
33+
- `config.resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to empty profile
34+
and auth state on login
3335
- `config.enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable
3436
auth redirect handling listener. (default: `true`)
3537
- `config.onAuthStateChanged` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function run when auth state

docs/api/constants.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Object containing all action types
3333
- `LOGIN_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/LOGIN_ERROR`
3434
- `NO_VALUE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/NO_VALUE`
3535
- `UNAUTHORIZED_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/UNAUTHORIZED_ERROR`
36+
- `ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/ERROR`
3637
- `UNSET_LISTENER` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/UNSET_LISTENER`
3738
- `AUTHENTICATION_INIT_STARTED` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTHENTICATION_INIT_STARTED`
3839
- `AUTHENTICATION_INIT_FINISHED` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTHENTICATION_INIT_FINISHED`
@@ -63,6 +64,8 @@ Default configuration options
6364
database logging is enabled.
6465
- `updateProfileOnLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to update
6566
user profile when logging in.
67+
- `resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to reset auth
68+
and profile when logging in (see issue #254 for more details).
6669
- `enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to enable
6770
redirect handling. This must be disabled if environment is not http/https
6871
such as with react-native.

docs/api/props-firebase.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ Firebase ref function
293293

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

296+
## auth
297+
298+
Firebase auth service instance including all Firebase auth methods
299+
300+
Returns [**Auth**](https://firebase.google.com/docs/reference/js/firebase.auth.Auth)
301+
296302
## database
297303

298304
Firebase database service instance including all Firebase storage methods
@@ -305,8 +311,8 @@ Firebase storage service instance including all Firebase storage methods
305311

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

308-
## auth
314+
## messaging
309315

310-
Firebase auth service instance including all Firebase auth methods
316+
Firebase messaging service instance including all Firebase messaging methods
311317

312-
Returns [**Auth**](https://firebase.google.com/docs/reference/js/firebase.auth.Auth)
318+
Returns **firebase.messaging** Firebase messaging service

docs/roadmap.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
*None Yet Planned*
3030

3131
#### Features
32-
* Config option for populated items updating when changed - [#69](https://github.com/prescottprue/react-redux-firebase/issues/69)
32+
* `preserveOnLogout` to preserve some data on logout (already supported in v2.0.0)
3333
* Population of ordered data (possibly `populatedOrderToJS`) - [#239](https://github.com/prescottprue/react-redux-firebase/issues/239)
34+
* `childAlias` to store populate result on another parameter - [#126](https://github.com/prescottprue/react-redux-firebase/issues/126)
35+
* `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)
36+
* Config option for populated items updating when changed - [#69](https://github.com/prescottprue/react-redux-firebase/issues/69)
37+
* 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)
3438
* Expose whole Firebase instance (warning: Using Firebase instance methods will not dispatch actions or update redux state)
35-
* Config option to not remove all data on logout (potential config syntax: `preserveOnLogout: ['todos']`)
36-
* 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).
37-
* 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)
38-
3939

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

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

@@ -72,10 +73,9 @@
7273
* `react-native` index file referenced in `package.json` that makes it no longer necessary to pass `ReactNative` in config
7374
* `AuthRequired` decorator (or decorator factory) that forces auth to exist before rendering component
7475
* Support native modules through [`react-native-firebase`](https://github.com/invertase/react-native-firebase) - [#131](https://github.com/prescottprue/react-redux-firebase/issues/131)
76+
* Detect Non-HTTP environments (such as with SSR) so that `enableRedirectHandling: false` is not required in config
7577
* Track online users and sessions by passing `presence` config option
76-
77-
#### Enhancements/Fixes
78-
* Implement [`firebase-server`](https://github.com/urish/firebase-server) for tests instead of using demo firebase instance
78+
* 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)
7979

8080
#### Under Consideration
8181
* Allowing `presence` setting to accept a function for dynamically building presence path based on auth

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "1.4.6",
3+
"version": "1.4.7",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
55
"browser": "dist/react-redux-firebase.js",
66
"main": "lib/index.js",

src/actions/auth.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,10 @@ export const init = (dispatch, firebase) => {
311311
* @private
312312
*/
313313
export const login = (dispatch, firebase, credentials) => {
314-
dispatchLoginError(dispatch, null)
314+
if (firebase._.config.resetBeforeLogin) {
315+
dispatchLoginError(dispatch, null)
316+
}
317+
315318
let { method, params } = getLoginMethodAndParams(firebase, credentials)
316319

317320
return firebase.auth()[method](...params)

src/compose.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ let firebaseInstance
2727
* database logging
2828
* @property {Boolean} config.updateProfileOnLogin - Whether or not to update
2929
* profile when logging in. (default: `false`)
30+
* @property {Boolean} config.resetBeforeLogin - Whether or not to empty profile
31+
* and auth state on login
3032
* @property {Boolean} config.enableRedirectHandling - Whether or not to enable
3133
* auth redirect handling listener. (default: `true`)
3234
* @property {Function} config.onAuthStateChanged - Function run when auth state
@@ -431,25 +433,31 @@ export default (fbConfig, otherConfig) => next =>
431433
/**
432434
* @name ref
433435
* @description Firebase ref function
434-
* @return {database.Reference}
436+
* @return {firebase.database.Reference}
437+
* @private
438+
*/
439+
/**
440+
* @name database
441+
* @description Firebase database service instance including all Firebase storage methods
442+
* @return {firebase.database} Firebase database service
443+
* @private
444+
*/
445+
/**
446+
* @name storage
447+
* @description Firebase storage service instance including all Firebase storage methods
448+
* @return {firebase.storage} Firebase storage service
449+
* @private
450+
*/
451+
/**
452+
* @name messaging
453+
* @description Firebase messaging service instance including all Firebase messaging methods
454+
* @return {firebase.messaging} Firebase messaging service
435455
* @private
436456
*/
437-
/**
438-
* @name database
439-
* @description Firebase database service instance including all Firebase storage methods
440-
* @return {Database} Firebase database service
441-
* @private
442-
*/
443-
/**
444-
* @name storage
445-
* @description Firebase storage service instance including all Firebase storage methods
446-
* @return {Storage} Firebase storage service
447-
* @private
448-
*/
449457
/**
450458
* @name auth
451459
* @description Firebase auth service instance including all Firebase auth methods
452-
* @return {Auth}
460+
* @return {firebase.auth} Firebase auth service
453461
* @private
454462
*/
455463
firebase.helpers = {
@@ -473,7 +481,8 @@ export default (fbConfig, otherConfig) => next =>
473481
verifyPasswordResetCode,
474482
watchEvent,
475483
unWatchEvent,
476-
storage: () => firebase.storage()
484+
storage: () => firebase.storage(),
485+
messaging: () => firebase.messaging()
477486
}
478487

479488
authActions.init(dispatch, instance)

src/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const actionsPrefix = '@@reactReduxFirebase'
1919
* @property {String} LOGIN_ERROR - `@@reactReduxFirebase/LOGIN_ERROR`
2020
* @property {String} NO_VALUE - `@@reactReduxFirebase/NO_VALUE`
2121
* @property {String} UNAUTHORIZED_ERROR - `@@reactReduxFirebase/UNAUTHORIZED_ERROR`
22+
* @property {String} ERROR - `@@reactReduxFirebase/ERROR`
2223
* @property {String} UNSET_LISTENER - `@@reactReduxFirebase/UNSET_LISTENER`
2324
* @property {String} AUTHENTICATION_INIT_STARTED - `@@reactReduxFirebase/AUTHENTICATION_INIT_STARTED`
2425
* @property {String} AUTHENTICATION_INIT_FINISHED - `@@reactReduxFirebase/AUTHENTICATION_INIT_FINISHED`
@@ -65,6 +66,8 @@ export const actionTypes = {
6566
* database logging is enabled.
6667
* @property {Boolean} updateProfileOnLogin - `true` Whether or not to update
6768
* user profile when logging in.
69+
* @property {Boolean} resetBeforeLogin - `true` Whether or not to reset auth
70+
* and profile when logging in (see issue #254 for more details).
6871
* @property {Boolean} enableRedirectHandling - `true` Whether or not to enable
6972
* redirect handling. This must be disabled if environment is not http/https
7073
* such as with react-native.
@@ -84,6 +87,7 @@ export const actionTypes = {
8487
export const defaultConfig = {
8588
userProfile: null,
8689
enableLogging: false,
90+
resetBeforeLogin: true,
8791
updateProfileOnLogin: true,
8892
enableRedirectHandling: true,
8993
autoPopulateProfile: true,

tests/unit/actions/auth.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global describe expect it beforeEach */
21
import {
32
dispatchLoginError,
43
dispatchUnauthorizedError,

tests/unit/library.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global describe expect it */
21
import src from '../../src'
32

43
describe('module', () => {

tests/unit/utils/auth.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global firebase describe expect it */
21
import {
32
createAuthProvider,
43
getLoginMethodAndParams

tests/unit/utils/events.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global describe expect it beforeEach */
21
import { getEventsFromInput } from '../../../src/utils/events'
32

43
describe('Utils: Events', () => {

tests/unit/utils/populate.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global describe expect it beforeEach */
21
import {
32
getPopulateObj,
43
getPopulates,

tests/unit/utils/query.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global describe expect it beforeEach */
21
import {
32
getWatchPath,
43
setWatcher,

tests/unit/utils/storage.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global describe expect it */
21
import { deleteFile } from '../../../src/utils/storage'
32
const fakeFirebase = {
43
_: {

0 commit comments

Comments
 (0)