Skip to content

Commit 362f992

Browse files
committed
Switch useUpdate to useSet
1 parent 41a8471 commit 362f992

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

docs/api/firebaseInstance.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,11 @@ internally while updating profile on Firestore uses `set` with
397397
- `profileUpdate` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Profile data to place in new profile
398398
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options object (used to change how profile
399399
update occurs)
400-
- `options.useUpdate` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Use update instead of set with merge
401-
(only used when updating profile on Firestore)
402-
- `options.merge` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to use merge when setting
403-
(only used when updating profile on Firestore)
400+
- `options.useSet` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Use set with merge instead of
401+
update. Setting to `false` uses update (can cause issue of profile document
402+
does not exist). Note: Only used when updating profile on Firestore (optional, default `true`)
403+
- `options.merge` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to use merge when
404+
setting profile. Note: Only used when updating profile on Firestore (optional, default `true`)
404405

405406
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
406407

src/createFirebaseInstance.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,11 @@ export const createFirebaseInstance = (firebase, configs, dispatch) => {
415415
* @param {Object} profileUpdate - Profile data to place in new profile
416416
* @param {Object} options - Options object (used to change how profile
417417
* update occurs)
418-
* @param {Boolean} options.useUpdate - Use update instead of set with merge
419-
* (only used when updating profile on Firestore)
420-
* @param {Boolean} options.merge - Whether or not to use merge when setting
421-
* (only used when updating profile on Firestore)
418+
* @param {Boolean} [options.useSet=true] - Use set with merge instead of
419+
* update. Setting to `false` uses update (can cause issue of profile document
420+
* does not exist). Note: Only used when updating profile on Firestore
421+
* @param {Boolean} [options.merge=true] - Whether or not to use merge when
422+
* setting profile. Note: Only used when updating profile on Firestore
422423
* @return {Promise}
423424
*/
424425
const updateProfile = (profileUpdate, options) =>

src/utils/auth.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,24 @@ export const updateProfileOnRTDB = (firebase, profileUpdate) => {
197197
* @param {Object} profileUpdate - Updates to profile object
198198
* @param {Object} options - Options object for configuring how profile
199199
* update occurs
200-
* @param {Boolean} options.useUpdate - Use update instead of set with merge
201-
* @param {Boolean} options.merge - Whether or not to use merge when setting
202-
* profile
200+
* @param {Boolean} [options.useSet=true] - Use set with merge instead of
201+
* update. Setting to `false` uses update (can cause issue of profile document
202+
* does not exist).
203+
* @param {Boolean} [options.merge=true] - Whether or not to use merge when
204+
* setting profile
203205
* @return {Promise} Resolves with results of profile get
204206
*/
205207
export const updateProfileOnFirestore = (
206208
firebase,
207209
profileUpdate,
208210
options = {}
209211
) => {
210-
const { useUpdate = false, merge = true } = options
212+
const { useSet = true, merge = true } = options
211213
const { firestore, _: { config, authUid } } = firebase
212214
const profileRef = firestore().doc(`${config.userProfile}/${authUid}`)
213-
const profileUpdatePromise = useUpdate
215+
// Use set with merge (to prevent "No document to update") unless otherwise
216+
// specificed through options
217+
const profileUpdatePromise = useSet
214218
? profileRef.set(profileUpdate, { merge })
215219
: profileRef.update(profileUpdate)
216220
return profileUpdatePromise.then(() => profileRef.get())

0 commit comments

Comments
 (0)