Skip to content

Commit 092e394

Browse files
prescottprueMatthewDaileyAlexanderArvidssonssdns
authored
v3.9.0 (#1050)
* fix(auth): prevent throw in `logout` when database is not setup (#1042) - @ssdns * fix(types): fix `reloadAuth` argument type and duplicate of `endBefore` (#1031) - @ MatthewDailey * fix(types): fix argument type for `login` with credentials (#1045) - @AlexanderArvidsson * fix(types): add back `FirestoreStatics` to `ExtendedFirestoreInstance` (#1030) * fix(core): add deprecation message `enableLogging` config option * chore(docs): add note about required rules for profile settings (#1049) Co-authored-by: Matthew Dailey <[email protected]> Co-authored-by: Alexander Arvidsson <[email protected]> Co-authored-by: shishido <[email protected]>
2 parents c4a56ae + f4d9288 commit 092e394

File tree

19 files changed

+511
-657
lines changed

19 files changed

+511
-657
lines changed

docs/api/constants.md

+123-138
Large diffs are not rendered by default.

docs/api/firebaseInstance.md

+277-394
Large diffs are not rendered by default.

docs/api/useFirebaseConnect.md

+20-53
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
### Table of Contents
44

5-
- [useFirebaseConnect][1]
6-
- [Parameters][2]
7-
- [Examples][3]
5+
- [useFirebaseConnect][1]
6+
- [Parameters][2]
7+
- [Examples][3]
88

99
## useFirebaseConnect
1010

11-
1211
Hook that automatically listens/unListens to provided firebase paths
1312
using React's useEffect hook.
1413

1514
### Parameters
1615

17-
- `queriesConfig` **([object][5] \| [string][6] \| [Function][7] \| [Array][8])** Object, string, or
18-
array contains object or string for path to sync from Firebase or null if
19-
hook doesn't need to sync. Can also be a function that returns an object,
20-
a path string, or array of an object or a path string.
16+
- `queriesConfig` **([Function][5] \| [Array][6])** Object, string, or
17+
array contains object or string for path to sync from Firebase or null if
18+
hook doesn't need to sync. Can also be a function that returns an object,
19+
a path string, or array of an object or a path string.
2120

2221
### Examples
2322

@@ -30,14 +29,10 @@ import { useFirebaseConnect } from 'react-redux-firebase'
3029

3130
export default function Todos() {
3231
// sync /todos from firebase into redux
33-
useFirebaseConnect('todos')
32+
useFirebaseConnect(['todos'])
3433
// Connect to redux state using selector hook
35-
const todos = useSelector(state => state.firebase.data.todos)
36-
return (
37-
<div>
38-
{JSON.stringify(todos, null, 2)}
39-
</div>
40-
)
34+
const todos = useSelector((state) => state.firebase.data.todos)
35+
return <div>{JSON.stringify(todos, null, 2)}</div>
4136
}
4237
```
4338

@@ -50,49 +45,21 @@ import { useSelector } from 'react-redux'
5045
import { useFirebaseConnect } from 'react-redux-firebase'
5146

5247
export default function Post({ postId }) {
53-
useFirebaseConnect(`posts/${postId}`) // sync /posts/postId from firebase into redux
54-
const post = useSelector(({ firebase: { ordered: { posts } } }) => posts && posts[postId])
55-
return (
56-
<div>
57-
{JSON.stringify(post, null, 2)}
58-
</div>
59-
)
60-
}
61-
```
62-
63-
_Data that depends on props, an array as a query_
64-
65-
```javascript
66-
import React from 'react'
67-
import { compose } from 'redux'
68-
import { useSelector } from 'react-redux'
69-
import { useFirebaseConnect, getVal } from 'react-redux-firebase'
70-
71-
export default function Post({ postId }) {
72-
useFirebaseConnect([`posts/${postId}`], [postId]) // sync /posts/postId from firebase into redux
73-
const post = useSelector(state => {
74-
return state.firebase.ordered.posts && state.firebase.ordered.posts[postId]
75-
})
76-
return (
77-
<div>
78-
{JSON.stringify(post, null, 2)}
79-
</div>
48+
useFirebaseConnect([`posts/${postId}`]) // sync /posts/postId from firebase into redux
49+
const post = useSelector(
50+
({
51+
firebase: {
52+
ordered: { posts }
53+
}
54+
}) => posts && posts[postId]
8055
)
56+
return <div>{JSON.stringify(post, null, 2)}</div>
8157
}
8258
```
8359

8460
[1]: #usefirebaseconnect
85-
8661
[2]: #parameters
87-
8862
[3]: #examples
89-
9063
[4]: https://react-redux-firebase.com/docs/api/useFirebaseConnect.html
91-
92-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
93-
94-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
95-
96-
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
97-
98-
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
64+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
65+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

docs/api/useFirestoreConnect.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Populate is supported for Firestore as of v0.6.0 of redux-firestore (added
1616

1717
### Parameters
1818

19-
- `queriesConfigs` **([object][6] \| [string][7] \| [Array][8] \| [Function][9])** An object, string,
19+
- `queriesConfigs` **([Array][6] \| [Function][7])** An object, string,
2020
or array of object or string for paths to sync from firestore. Can also be
2121
a function that returns the object, string, or array of object or string.
2222

@@ -72,7 +72,5 @@ export default function TodoItem({ todoId }) {
7272
[3]: #examples
7373
[4]: https://react-redux-firebase.com/docs/api/useFirestoreConnect.html
7474
[5]: https://github.com/prescottprue/redux-firestore/issues/48
75-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
76-
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
77-
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
78-
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
75+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
76+
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function

docs/integrations/redux-saga.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,33 @@ import { applyMiddleware, compose, createStore } from 'redux'
77
import { browserHistory } from 'react-router'
88
import makeRootReducer from './reducers'
99
import createSagaMiddleware from 'redux-saga'
10-
import firebase from 'firebase/app';
11-
import 'firebase/database';
10+
import firebase from 'firebase/app'
11+
import 'firebase/database'
1212

1313
const firebaseConfig = {} // firebase configuration including databaseURL
1414
const reduxFirebase = {
15-
userProfile: 'users',
16-
enableLogging: 'false'
15+
userProfile: 'users'
1716
}
1817

19-
firebase.initializeApp(firebaseConfig);
18+
firebase.initializeApp(firebaseConfig)
2019

2120
function* helloSaga() {
2221
try {
2322
yield firebase.ref('/some/path').push({ nice: 'work!' })
24-
} catch(err) {
23+
} catch (err) {
2524
console.log('Error in saga!:', err)
2625
}
2726
}
2827

2928
export default (initialState = {}, history) => {
30-
3129
const sagaMiddleware = createSagaMiddleware() // create middleware
3230

33-
const middleware = [ sagaMiddleware ]
31+
const middleware = [sagaMiddleware]
3432

3533
const store = createStore(
3634
makeRootReducer(),
3735
{}, // initial state
38-
compose(
39-
applyMiddleware(...middleware)
40-
)
36+
compose(applyMiddleware(...middleware))
4137
)
4238

4339
return store

docs/recipes/profile.md

+41-24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ Include the `userProfile` parameter in config passed to react-redux-firebase:
1010

1111
```js
1212
const config = {
13-
userProfile: 'users', // where profiles are stored in database
13+
userProfile: 'users' // where profiles are stored in database
14+
}
15+
```
16+
17+
Make sure to set your database rules to work with user profiles being stored under the `users` path of Real Time Database:
18+
19+
```json
20+
{
21+
"rules": {
22+
"users": {
23+
"$userId": {
24+
".read": "$userId === auth.uid",
25+
".write": "$userId === auth.uid"
26+
}
27+
}
28+
}
1429
}
1530
```
1631

@@ -24,7 +39,7 @@ Then later `connect` (from [react-redux](https://github.com/reactjs/react-redux/
2439
import { useSelector } from 'react-redux'
2540

2641
function SomeComponent() {
27-
const profile = useSelector(state => state.firebase.profile)
42+
const profile = useSelector((state) => state.firebase.profile)
2843
return <div>{JSON.stringify(profile, null, 2)}</div>
2944
}
3045

@@ -42,13 +57,11 @@ Then later `connect` (from [react-redux](https://github.com/reactjs/react-redux/
4257
import { connect } from 'react-redux'
4358

4459
// grab profile from redux with connect
45-
connect(
46-
(state) => {
47-
return {
48-
profile: state.firebase.profile // profile passed as props.profile
49-
}
60+
connect((state) => {
61+
return {
62+
profile: state.firebase.profile // profile passed as props.profile
5063
}
51-
)(SomeComponent) // pass component to be wrapped
64+
})(SomeComponent) // pass component to be wrapped
5265

5366
// or with some shorthand:
5467
connect(({ firebase: { profile } }) => ({ profile }))(SomeComponent)
@@ -65,6 +78,19 @@ const config = {
6578
}
6679
```
6780

81+
Make sure to set your firestore rules to work with user profiles being stored under the `users` collection of Firestore:
82+
83+
```
84+
rules_version = '2';
85+
service cloud.firestore {
86+
match /databases/{database}/documents {
87+
match /users/{userId} {
88+
allow read, write: if request.auth.uid == userId;
89+
}
90+
}
91+
}
92+
```
93+
6894
## Update Profile
6995

7096
The current users profile can be updated by using the `updateProfile` method:
@@ -78,7 +104,7 @@ import { useFirebase, isLoaded } from 'react-redux-firebase'
78104

79105
export default function UpdateProfilePage() {
80106
const firebase = useFirebase()
81-
const profile = useSelector(state => state.firebase.profile)
107+
const profile = useSelector((state) => state.firebase.profile)
82108

83109
function updateUserProfile() {
84110
return firebase.updateProfile({ role: 'admin' })
@@ -87,18 +113,10 @@ export default function UpdateProfilePage() {
87113
return (
88114
<div>
89115
<h2>Update User Profile</h2>
90-
<span>
91-
Click the button to update profile to include role parameter
92-
</span>
93-
<button onClick={updateUserProfile}>
94-
Add Role To User
95-
</button>
116+
<span>Click the button to update profile to include role parameter</span>
117+
<button onClick={updateUserProfile}>Add Role To User</button>
96118
<div>
97-
{
98-
isLoaded(profile)
99-
? JSON.stringify(profile, null, 2)
100-
: 'Loading...'
101-
}
119+
{isLoaded(profile) ? JSON.stringify(profile, null, 2) : 'Loading...'}
102120
</div>
103121
</div>
104122
)
@@ -113,7 +131,8 @@ The way user profiles are written to the database can be modified by passing the
113131
// within your createStore.js or store.js file include the following config
114132
const config = {
115133
userProfile: 'users', // where profiles are stored in database
116-
profileFactory: (userData, profileData, firebase) => { // how profiles are stored in database
134+
profileFactory: (userData, profileData, firebase) => {
135+
// how profiles are stored in database
117136
const { user } = userData
118137
return {
119138
email: user.email
@@ -152,9 +171,7 @@ Setting config like this:
152171
```js
153172
const config = {
154173
userProfile: 'users', // where profiles are stored in database
155-
profileParamsToPopulate: [
156-
'contacts:users'
157-
]
174+
profileParamsToPopulate: ['contacts:users']
158175
}
159176
```
160177

examples/complete/firestore/src/config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export const firebase = {
99

1010
export const rrfConfig = {
1111
userProfile: 'users',
12-
useFirestoreForProfile: true, // Store in Firestore instead of Real Time DB
13-
enableLogging: false
12+
useFirestoreForProfile: true // Store in Firestore instead of Real Time DB
1413
}
1514

1615
export default { firebase, rrfConfig }

examples/complete/react-native/config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export const firebase = {
99

1010
export const rrfConfig = {
1111
userProfile: 'users',
12-
useFirestoreForProfile: true, // Store in Firestore instead of Real Time DB
13-
enableLogging: false
12+
useFirestoreForProfile: true // Store in Firestore instead of Real Time DB
1413
}
1514

1615
export default { firebase, rrfConfig }

examples/complete/react-native/store.js

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default function configureStore(initialState, history) {
1515
reactReduxFirebase(firebase, {
1616
userProfile: 'users',
1717
useFirestoreForProfile: true, // Store in Firestore instead of Real Time DB
18-
enableLogging: false
1918
})
2019
)(createStore)
2120

examples/complete/simple/src/config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export const firebase = {
99

1010
export const reduxFirebase = {
1111
userProfile: 'users',
12-
useFirestoreForProfile: true,
13-
enableLogging: false
12+
useFirestoreForProfile: true
1413
}
1514

1615
export default { firebase, reduxFirebase }

examples/complete/typescript/src/App.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import { firebase as fbConfig, reduxFirebase as rfConfig } from "./config";
99
import Home from "./Home";
1010
import configureStore from "./store";
1111

12-
const initialState = {};
13-
const store = configureStore(initialState);
12+
const store = configureStore();
1413
// Initialize Firebase instance
1514
firebase.initializeApp(fbConfig);
1615

examples/complete/typescript/src/config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export const firebase = {
99

1010
export const reduxFirebase = {
1111
userProfile: 'users',
12-
useFirestoreForProfile: true,
13-
enableLogging: false
12+
useFirestoreForProfile: true
1413
}
1514

1615
export default { firebase, reduxFirebase }

examples/snippets/webpack2/src/store.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default function configureStore (initialState, history) {
88
reactReduxFirebase(fbConfig,
99
{
1010
userProfile: 'users',
11-
enableLogging: false
1211
}
1312
),
1413
typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f

0 commit comments

Comments
 (0)