@@ -10,7 +10,22 @@ Include the `userProfile` parameter in config passed to react-redux-firebase:
10
10
11
11
``` js
12
12
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
+ }
14
29
}
15
30
```
16
31
@@ -24,7 +39,7 @@ Then later `connect` (from [react-redux](https://github.com/reactjs/react-redux/
24
39
import { useSelector } from ' react-redux'
25
40
26
41
function SomeComponent () {
27
- const profile = useSelector (state => state .firebase .profile )
42
+ const profile = useSelector (( state ) => state .firebase .profile )
28
43
return < div> {JSON .stringify (profile, null , 2 )}< / div>
29
44
}
30
45
@@ -42,13 +57,11 @@ Then later `connect` (from [react-redux](https://github.com/reactjs/react-redux/
42
57
import { connect } from ' react-redux'
43
58
44
59
// 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
50
63
}
51
- )(SomeComponent) // pass component to be wrapped
64
+ } )(SomeComponent) // pass component to be wrapped
52
65
53
66
// or with some shorthand:
54
67
connect (({ firebase: { profile } }) => ({ profile }))(SomeComponent)
@@ -65,6 +78,19 @@ const config = {
65
78
}
66
79
```
67
80
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
+
68
94
## Update Profile
69
95
70
96
The current users profile can be updated by using the ` updateProfile ` method:
@@ -78,7 +104,7 @@ import { useFirebase, isLoaded } from 'react-redux-firebase'
78
104
79
105
export default function UpdateProfilePage () {
80
106
const firebase = useFirebase ()
81
- const profile = useSelector (state => state .firebase .profile )
107
+ const profile = useSelector (( state ) => state .firebase .profile )
82
108
83
109
function updateUserProfile () {
84
110
return firebase .updateProfile ({ role: ' admin' })
@@ -87,18 +113,10 @@ export default function UpdateProfilePage() {
87
113
return (
88
114
< div>
89
115
< 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>
96
118
< div>
97
- {
98
- isLoaded (profile)
99
- ? JSON .stringify (profile, null , 2 )
100
- : ' Loading...'
101
- }
119
+ {isLoaded (profile) ? JSON .stringify (profile, null , 2 ) : ' Loading...' }
102
120
< / div>
103
121
< / div>
104
122
)
@@ -113,7 +131,8 @@ The way user profiles are written to the database can be modified by passing the
113
131
// within your createStore.js or store.js file include the following config
114
132
const config = {
115
133
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
117
136
const { user } = userData
118
137
return {
119
138
email: user .email
@@ -152,9 +171,7 @@ Setting config like this:
152
171
``` js
153
172
const config = {
154
173
userProfile: ' users' , // where profiles are stored in database
155
- profileParamsToPopulate: [
156
- ' contacts:users'
157
- ]
174
+ profileParamsToPopulate: [' contacts:users' ]
158
175
}
159
176
```
160
177
0 commit comments