Skip to content

Commit

Permalink
fix(actionRecordMiddleware): expand sanitizeData (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Apr 15, 2021
1 parent 4a1f85b commit 21388b3
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/redux/middleware/actionRecordMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { platformApiTypes } from '../../types';
import { userTypes } from '../types/userTypes';

/**
* Modify actions' payload for privacy.
Expand Down Expand Up @@ -31,25 +30,34 @@ const sanitizeActionHeaders = ({ payload, ...action }) => {
* @returns {object}
*/
const sanitizeData = ({ type, payload, ...action }) => {
if (payload && new RegExp(userTypes.USER_AUTH).test(type)) {
const updatedPayload = {
...payload,
data: {
...payload?.data,
user: {
...payload?.data?.user,
[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY]: {
...payload?.data?.user[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY],
[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY_TYPES.USER]: {}
const removeUserIdentity = obj => {
if (obj?.data?.user?.[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY]) {
return {
...obj,
data: {
...obj.data,
user: {
...obj.data.user,
[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY]: {
...obj.data.user[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY],
[platformApiTypes.PLATFORM_API_RESPONSE_USER_IDENTITY_TYPES.USER]: {}
}
}
}
}
};
};
}

return undefined;
};

const updatedPayload = removeUserIdentity(payload) || payload;
const updatedAction = removeUserIdentity(action) || action;

return { type, payload: updatedPayload, ...action };
if (updatedPayload) {
return { type, payload: updatedPayload, ...updatedAction };
}

return { type, ...action };
return { type, ...updatedAction };
};

/**
Expand Down

0 comments on commit 21388b3

Please sign in to comment.