Skip to content

Commit 07aa0d2

Browse files
authored
* fix(auth): add warning for invalid auth providers - prescottprue#559 * fix(docs): cleanup redux-persist example to remove autoRehydrate - prescottprue#545 * fix(docs): update SSR docs to include a section about Firestore - prescottprue#456 * fix(docs): update docs to have redux-auth-wrapper v2 examples above older examples - prescottprue#542
1 parent 5d57182 commit 07aa0d2

File tree

7 files changed

+3303
-3291
lines changed

7 files changed

+3303
-3291
lines changed

docs/integrations/redux-persist.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ Usage with [redux-persist](https://github.com/rt2zz/redux-persist) depends on wh
77
*createStore.js*
88

99
```js
10-
import { browserHistory } from 'react-router'
1110
import { createStore, compose } from 'redux'
1211
import { reactReduxFirebase } from 'react-redux-firebase'
1312
import firebase from 'firebase/app'
1413
import 'firebase/auth'
1514
import 'firebase/database'
16-
import { persistStore, persistReducer, autoRehydrate } from 'redux-persist'
15+
import { persistStore, persistReducer } from 'redux-persist'
1716
import localStorage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native
1817
import makeRootReducer from './reducers'
1918
import { updateLocation } from './location'
@@ -37,14 +36,10 @@ export default (initialState = {}, history) => {
3736
persistedReducer,
3837
initialState,
3938
compose(
40-
reactReduxFirebase(firebase, reduxConfig),
41-
autoRehydrate()
39+
reactReduxFirebase(firebase, reduxConfig)
4240
)
4341
)
4442

45-
// To unsubscribe, invoke `store.unsubscribeHistory()` anytime
46-
store.unsubscribeHistory = browserHistory.listen(updateLocation(store))
47-
4843
const persistor = persistStore(store)
4944

5045
return { store, persistor }
@@ -99,7 +94,6 @@ export default function makeRootReducer() {
9994
}
10095
```
10196

102-
10397
*App.js*
10498

10599
```js

docs/recipes/routing.md

+50-41
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,19 @@ Using [`redux-auth-wrapper`](https://github.com/mjrussell/redux-auth-wrapper) yo
4646

4747
In order to only allow authenticated users to view a page, a `UserIsAuthenticated` Higher Order Component can be created:
4848

49-
**redux-auth-wrapper v1**
50-
51-
```javascript
52-
import { browserHistory } from 'react-router'
53-
import { UserAuthWrapper } from 'redux-auth-wrapper'
54-
55-
export const UserIsAuthenticated = UserAuthWrapper({
56-
wrapperDisplayName: 'UserIsAuthenticated',
57-
authSelector: ({ firebase: { auth } }) => auth,
58-
authenticatingSelector: ({ firebase: { auth, isInitializing } }) =>
59-
!auth.isLoaded || isInitializing === true,
60-
predicate: auth => !auth.isEmpty,
61-
redirectAction: (newLoc) => (dispatch) => {
62-
browserHistory.replace(newLoc)
63-
// routerActions.replace // if using react-router-redux
64-
dispatch({
65-
type: 'UNAUTHED_REDIRECT',
66-
payload: { message: 'You must be authenticated.' },
67-
})
68-
}
69-
})
70-
```
7149

7250
**react-router v4 + redux-auth-wrapper v2**
7351

52+
Make sure to install `history` using `npm i --save history`
53+
7454
```javascript
7555
import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper';
7656
import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect'
77-
import LoadingScreen from '../components/LoadingScreen'; // change it to your custom component
57+
import createHistory from 'history/createBrowserHistory'
58+
import LoadingScreen from 'components/LoadingScreen'; // change it to your custom component
7859

7960
const locationHelper = locationHelperBuilder({});
61+
const history = createHistory()
8062

8163
export const UserIsAuthenticated = connectedRouterRedirect({
8264
wrapperDisplayName: 'UserIsAuthenticated',
@@ -111,9 +93,14 @@ export const UserIsNotAuthenticated = connectedRouterRedirect({
11193
});
11294
```
11395

114-
11596
Then it can be used as a Higher Order Component wrapper on a component:
11697

98+
*standard ES5/ES6*
99+
100+
```javascript
101+
export default UserIsAuthenticated(ProtectedThing)
102+
```
103+
117104
*es7 decorators*
118105

119106
```javascript
@@ -129,12 +116,6 @@ export default class ProtectedThing extends Component {
129116
}
130117
```
131118

132-
*standard ES5/ES6*
133-
134-
```javascript
135-
export default UserIsAuthenticated(ProtectedThing)
136-
```
137-
138119
Or it can be used at the route level:
139120

140121
```javascript
@@ -145,39 +126,43 @@ Or it can be used at the route level:
145126
```
146127

147128

148-
### Redirect Authenticated
149-
Just as easily as creating a wrapper for redirect if a user is not logged in, we can create one that redirects if a user *IS* authenticated. This can be useful for pages that you do not want a logged in user to see, such as the login page.
150-
151-
**react-router v3 and earlier**
129+
**redux-auth-wrapper v1**
152130

153131
```javascript
154132
import { browserHistory } from 'react-router'
155133
import { UserAuthWrapper } from 'redux-auth-wrapper'
156-
import LoadingScreen from '../components/LoadingScreen'; // change it to your custom component
157134

158-
export const UserIsNotAuthenticated = UserAuthWrapper({
159-
failureRedirectPath: '/',
135+
export const UserIsAuthenticated = UserAuthWrapper({
136+
wrapperDisplayName: 'UserIsAuthenticated',
160137
authSelector: ({ firebase: { auth } }) => auth,
161138
authenticatingSelector: ({ firebase: { auth, isInitializing } }) =>
162139
!auth.isLoaded || isInitializing === true,
163-
predicate: auth => auth.isEmpty,
140+
predicate: auth => !auth.isEmpty,
164141
redirectAction: (newLoc) => (dispatch) => {
165142
browserHistory.replace(newLoc)
143+
// routerActions.replace // if using react-router-redux
166144
dispatch({
167-
type: 'AUTHED_REDIRECT',
168-
payload: { message: 'User is authenticated. Redirecting home...' }
145+
type: 'UNAUTHED_REDIRECT',
146+
payload: { message: 'You must be authenticated.' },
169147
})
170148
}
171149
})
172150
```
173151

152+
### Redirect Authenticated
153+
154+
Just as easily as creating a wrapper for redirect if a user is not logged in, we can create one that redirects if a user *IS* authenticated. This can be useful for pages that you do not want a logged in user to see, such as the login page.
155+
174156
**react-router v4 + redux-auth-wrapper v2**
175157

176158
```js
177159
import locationHelperBuilder from 'redux-auth-wrapper/history4/locationHelper';
178160
import { connectedRouterRedirect } from 'redux-auth-wrapper/history4/redirect'
161+
import createHistory from 'history/createBrowserHistory'
162+
import LoadingScreen from 'components/LoadingScreen'; // change it to your custom component
179163

180-
import LoadingScreen from '../components/LoadingScreen'; // change it to your custom component
164+
const locationHelper = locationHelperBuilder({})
165+
const history = createHistory()
181166

182167
export const UserIsNotAuthenticated = connectedRouterRedirect({
183168
wrapperDisplayName: 'UserIsNotAuthenticated',
@@ -190,6 +175,7 @@ export const UserIsNotAuthenticated = connectedRouterRedirect({
190175
authenticatedSelector: ({ firebase: { auth } }) =>
191176
auth.isLoaded && auth.isEmpty,
192177
redirectAction: newLoc => (dispatch) => {
178+
history.push(newLoc)
193179
// routerActions.replace or other redirect
194180
dispatch({ type: 'UNAUTHED_REDIRECT' });
195181
},
@@ -216,3 +202,26 @@ export default compose(
216202
withFirebase // adds this.props.firebase
217203
)
218204
```
205+
206+
**react-router v3 and earlier + redux-auth-wrapper v1**
207+
208+
```javascript
209+
import { browserHistory } from 'react-router'
210+
import { UserAuthWrapper } from 'redux-auth-wrapper'
211+
import LoadingScreen from '../components/LoadingScreen'; // change it to your custom component
212+
213+
export const UserIsNotAuthenticated = UserAuthWrapper({
214+
failureRedirectPath: '/',
215+
authSelector: ({ firebase: { auth } }) => auth,
216+
authenticatingSelector: ({ firebase: { auth, isInitializing } }) =>
217+
!auth.isLoaded || isInitializing === true,
218+
predicate: auth => auth.isEmpty,
219+
redirectAction: (newLoc) => (dispatch) => {
220+
browserHistory.replace(newLoc)
221+
dispatch({
222+
type: 'AUTHED_REDIRECT',
223+
payload: { message: 'User is authenticated. Redirecting home...' }
224+
})
225+
}
226+
})
227+
```

docs/recipes/ssr.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Server Side Rendering
22

3-
43
## Preload Data
4+
Preloading data is a common step to in serverside rendering. How it is done differs based on whether you are using Real Time Database or Firestore.
55

6+
**Real Time Database**
67
`promiseEvents`, which is similar to `firebaseConnect` expected it is presented as a function instead of a React Component.
78

89
After creating your store:
@@ -18,6 +19,16 @@ store.firebase // getFirebase can also be used
1819
})
1920
```
2021

22+
**Firestore**
23+
Its just as simple as calling the built in get method with your query config:
24+
25+
```js
26+
store.firestore.get({ collection: 'todos' }) // or .get('todos')
27+
.then(() => {
28+
console.log('data is loaded into redux store')
29+
})
30+
```
31+
2132
## Troubleshooting
2233

2334
### Include XMLHttpRequest

examples/complete/material/project.config.js

-41
This file was deleted.

0 commit comments

Comments
 (0)