@@ -10,7 +10,22 @@ Include the `userProfile` parameter in config passed to react-redux-firebase:
1010
1111``` js
1212const 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/
2439import { useSelector } from ' react-redux'
2540
2641function 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/
4257import { 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:
5467connect (({ 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
7096The current users profile can be updated by using the ` updateProfile ` method:
@@ -78,7 +104,7 @@ import { useFirebase, isLoaded } from 'react-redux-firebase'
78104
79105export 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
114132const 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
153172const config = {
154173 userProfile: ' users' , // where profiles are stored in database
155- profileParamsToPopulate: [
156- ' contacts:users'
157- ]
174+ profileParamsToPopulate: [' contacts:users' ]
158175}
159176```
160177
0 commit comments