1- import { isArray , isString , isFunction , forEach , omit } from 'lodash'
1+ import { isArray , isString , isFunction , forEach , omit , pick } from 'lodash'
22import { actionTypes } from '../constants'
33import { populate } from '../helpers'
44import {
@@ -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 ,
0 commit comments