@@ -10,10 +10,9 @@ Routing can be changed based on data by using react lifecycle hooks such as `com
10
10
import React , { Component } from ' react'
11
11
import PropTypes from ' prop-types'
12
12
import { connect } from ' react-redux'
13
- import { firebaseConnect , isLoaded , isEmpty } from ' react-redux-firebase'
13
+ import { isLoaded , isEmpty } from ' react-redux-firebase'
14
14
15
15
const enhance = compose (
16
- firebaseConnect (),
17
16
connect (
18
17
({ firebase: { auth } }) => ({
19
18
auth, // state.firebase.auth -> props.auth
@@ -79,7 +78,7 @@ export const UserIsAuthenticated = UserAuthWrapper({
79
78
80
79
``` javascript
81
80
import locationHelperBuilder from ' redux-auth-wrapper/history4/locationHelper' ;
82
- import { browserHistory } from ' react-router ' ;
81
+ import { connectedRouterRedirect } from ' redux-auth-wrapper '
83
82
import LoadingScreen from ' ../components/LoadingScreen' ; // change it to your custom component
84
83
85
84
const locationHelper = locationHelperBuilder ({});
@@ -180,21 +179,26 @@ export const UserIsNotAuthenticated = UserAuthWrapper({
180
179
** react-router v4 + redux-auth-wrapper v2**
181
180
182
181
``` js
183
- import { browserHistory } from ' react-router'
184
- import { UserAuthWrapper } from ' redux-auth-wrapper'
182
+ import locationHelperBuilder from ' redux-auth-wrapper/history4/locationHelper' ;
183
+ import { connectedRouterRedirect } from ' redux-auth-wrapper'
184
+
185
185
import LoadingScreen from ' ../components/LoadingScreen' ; // change it to your custom component
186
186
187
- export const UserIsNotAuthenticated = UserAuthWrapper ({
187
+ export const UserIsNotAuthenticated = connectedRouterRedirect ({
188
188
wrapperDisplayName: ' UserIsNotAuthenticated' ,
189
- allowRedirectBack: false ,
190
189
AuthenticatingComponent: LoadingScreen,
190
+ allowRedirectBack: false ,
191
191
redirectPath : (state , ownProps ) =>
192
192
locationHelper .getRedirectQueryParam (ownProps) || ' /' ,
193
- authenticatedSelector : ({ firebase }) => pathToJS (firebase, ' auth' ) === null ,
194
- authenticatingSelector : ({ firebase }) =>
195
- pathToJS (firebase, ' isInitializing' ) === true ||
196
- pathToJS (firebase, ' auth' ) === undefined
197
- })
193
+ authenticatingSelector : ({ firebase: { auth, isInitializing } }) =>
194
+ ! auth .isLoaded || isInitializing === true ,
195
+ authenticatedSelector : ({ firebase: { auth } }) =>
196
+ auth .isLoaded && auth .isEmpty ,
197
+ redirectAction : newLoc => (dispatch ) => {
198
+ // routerActions.replace or other redirect
199
+ dispatch ({ type: ' UNAUTHED_REDIRECT' });
200
+ },
201
+ });
198
202
```
199
203
200
204
Can then be used on a Login route component:
0 commit comments