Skip to content

Commit bc74f57

Browse files
authored
fix(profile): profileFactory support for firestore - @compojoom
fix(profile): profileFactory support for firestore
2 parents 79eba5f + a8906f6 commit bc74f57

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/actions/auth.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const dispatchLoginError = (dispatch, authError) =>
2929
export const unWatchUserProfile = firebase => {
3030
const {
3131
authUid,
32-
config: { userProfile, useFirestoreForProfile }
32+
config: {userProfile, useFirestoreForProfile}
3333
} = firebase._
3434
if (firebase._.profileWatch) {
3535
if (useFirestoreForProfile && firebase.firestore) {
@@ -212,15 +212,23 @@ export const createUserProfile = (dispatch, firebase, userData, profile) => {
212212
.doc(userData.uid)
213213
.get()
214214
.then(profileSnap => {
215-
// Convert to JSON format (to prevent issue of writing invalid type to Firestore)
216-
const userDataObject = userData.toJSON ? userData.toJSON() : userData
217-
// Remove unnessesary auth params (configurable) and preserve types of timestamps
218-
const newProfile = {
219-
...omit(userDataObject, config.keysToRemoveFromAuth),
220-
avatarUrl: userDataObject.photoURL, // match profile pattern used for RTDB
221-
createdAt: stringToDate(userDataObject.createdAt),
222-
lastLoginAt: stringToDate(userDataObject.lastLoginAt)
215+
let newProfile = {}
216+
217+
// If the user did supply a profileFactory, we should use the result of it for the new Profile
218+
if (isFunction(config.profileFactory)) {
219+
newProfile = profile
220+
} else {
221+
// Convert to JSON format (to prevent issue of writing invalid type to Firestore)
222+
const userDataObject = userData.toJSON ? userData.toJSON() : userData
223+
// Remove unnecessary auth params (configurable) and preserve types of timestamps
224+
newProfile = {
225+
...omit(userDataObject, config.keysToRemoveFromAuth),
226+
avatarUrl: userDataObject.photoURL, // match profile pattern used for RTDB
227+
createdAt: stringToDate(userDataObject.metadata.creationTime),
228+
lastLoginAt: stringToDate(userDataObject.metadata.lastSignInTime)
229+
}
223230
}
231+
224232
// Return if config for updating profile is not enabled and profile exists
225233
if (!config.updateProfileOnLogin && profileSnap.exists) {
226234
return profileSnap.data()

0 commit comments

Comments
 (0)