Skip to content

Commit 44fa39d

Browse files
authored
v2.1.6
* fix(profile): profile created correctly regardless of custom objects in Firebase JS SDK response (newer versions) * feat(profile): add `console.error` for errors querying for profile population data (enabled using `logErrors` config option) * feat(query): switch `console.log` to `console.error` for query errors
1 parent 5011086 commit 44fa39d

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/actions/auth.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray, isString, isFunction, forEach, omit } from 'lodash'
1+
import { isArray, isString, isFunction, forEach, omit, pick } from 'lodash'
22
import { actionTypes } from '../constants'
33
import { populate } from '../helpers'
44
import {
@@ -75,7 +75,8 @@ export const handleProfileWatchResponse = (
7575
const {
7676
profileParamsToPopulate,
7777
autoPopulateProfile,
78-
useFirestoreForProfile
78+
useFirestoreForProfile,
79+
logErrors
7980
} = firebase._.config
8081
const profile = getProfileFromSnap(userProfileSnap)
8182
if (
@@ -121,6 +122,13 @@ export const handleProfileWatchResponse = (
121122
}
122123
})
123124
.catch(err => {
125+
if (logErrors) {
126+
// eslint-disable-next-line no-console
127+
console.error(
128+
`RRF: Error retrieving data for profile population. Firebase:`,
129+
err
130+
)
131+
}
124132
// Error retrieving data for population onto profile.
125133
dispatch({
126134
type: actionTypes.UNAUTHORIZED_ERROR,
@@ -248,6 +256,7 @@ export const createUserProfile = (dispatch, firebase, userData, profile) => {
248256
return profileSnap.data()
249257
}
250258
let newProfile = profile
259+
251260
// If the user did supply a profileFactory, we should use the result of it for the new Profile
252261
if (!newProfile) {
253262
// Convert to JSON format (to prevent issue of writing invalid type to Firestore)
@@ -261,6 +270,14 @@ export const createUserProfile = (dispatch, firebase, userData, profile) => {
261270
}
262271
}
263272

273+
// Convert custom object type within Provider data to a normal object
274+
if (isArray(newProfile.providerData)) {
275+
newProfile.providerData = newProfile.providerData.map(
276+
providerDataItem =>
277+
pick(providerDataItem, config.keysToPreserveFromProviderData)
278+
)
279+
}
280+
264281
// Create/Update the profile
265282
return profileSnap.ref
266283
.set(newProfile, { merge: true })
@@ -365,7 +382,7 @@ export const handleRedirectResult = (dispatch, firebase, authData) => {
365382
preserve: firebase._.config.preserveOnLogin
366383
})
367384

368-
createUserProfile(dispatch, firebase, user, {
385+
return createUserProfile(dispatch, firebase, user, {
369386
email: user.email,
370387
displayName: user.providerData[0].displayName || user.email,
371388
avatarUrl: user.providerData[0].photoURL,

src/constants.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ export const defaultConfig = {
207207
'redirectEventId',
208208
'stsTokenManager',
209209
'uid'
210+
],
211+
keysToPreserveFromProviderData: [
212+
'email',
213+
'phoneNumber',
214+
'photoURL',
215+
'providerId',
216+
'uid'
210217
]
211218
}
212219

0 commit comments

Comments
 (0)