Skip to content

Commit

Permalink
Merge pull request #1731 from tomivm/fix/avoid-store-boards-from-user…
Browse files Browse the repository at this point in the history
…Data

Save only necessary keys on local userData
  • Loading branch information
tomivm authored Jul 8, 2024
2 parents 8f11447 + 7b1be64 commit 2a8a659
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/components/App/App.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ export const APP_LANGS = [
'zh-CN',
'zu-ZA' // for crowdin contextual translation
];

export const USER_DATA_PROPERTIES = [
'id',
'google',
'facebook',
'apple',
'name',
'role',
'provider',
'locale',
'password',
'location',
'email',
'isFirstLogin',
'birthdate',
'lastlogin',
'createdAt',
'updatedAt',
'authToken'
];
16 changes: 13 additions & 3 deletions src/components/App/App.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
UPDATE_USER_DATA,
DISABLE_TOUR,
ENABLE_ALL_TOURS,
SET_UNLOGGED_USER_LOCATION
SET_UNLOGGED_USER_LOCATION,
USER_DATA_PROPERTIES
} from './App.constants';
import { LOGIN_SUCCESS, LOGOUT } from '../Account/Login/Login.constants';
import {
Expand Down Expand Up @@ -60,6 +61,15 @@ const initialState = {
userData: {}
};

const getKeysFromApiUserDataResponse = payload => {
const newUser = {};
if (!payload) return newUser;
USER_DATA_PROPERTIES.forEach(prop => {
if (payload[prop] !== undefined) newUser[prop] = payload[prop];
});
return newUser;
};

function appReducer(state = initialState, action) {
let displaySettings = { ...state.displaySettings };
let navigationSettings = { ...state.navigationSettings };
Expand Down Expand Up @@ -147,7 +157,7 @@ function appReducer(state = initialState, action) {
isFirstVisit: false,
displaySettings,
navigationSettings,
userData: action.payload || {}
userData: getKeysFromApiUserDataResponse(action.payload)
};
case LOGOUT:
return {
Expand All @@ -157,7 +167,7 @@ function appReducer(state = initialState, action) {
case UPDATE_USER_DATA:
return {
...state,
userData: action.userData
userData: getKeysFromApiUserDataResponse(action.userData)
};
case SET_UNLOGGED_USER_LOCATION:
return {
Expand Down

0 comments on commit 2a8a659

Please sign in to comment.