Skip to content

Commit 011c9de

Browse files
committed
chore: exclude PII user data fields from server sync
1 parent f9ed356 commit 011c9de

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/data-models/fields.ts

+6
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ enum PROTECTED_FIELDS {
2828
export const getProtectedFieldName = (key: IProtectedFieldName) => `_${PROTECTED_FIELDS[key]}`;
2929

3030
export type IProtectedFieldName = keyof typeof PROTECTED_FIELDS;
31+
32+
/** A list of protected fields that should not be synced to the server */
33+
export const EXCLUDED_FIELDS: IProtectedFieldName[] = [
34+
"AUTH_USER_DISPLAY_NAME",
35+
"AUTH_USER_PROFILE_IMAGE_URL",
36+
];

src/app/shared/services/server/server.service.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
22
import { Injectable } from "@angular/core";
33
import { DeviceInfo, Device } from "@capacitor/device";
4-
import { IAppConfig, getProtectedFieldName } from "data-models";
4+
import { IAppConfig, getProtectedFieldName, EXCLUDED_FIELDS } from "data-models";
55
import { interval } from "rxjs";
66
import { throwError } from "rxjs";
77
import { environment } from "src/environments/environment";
@@ -70,7 +70,9 @@ export class ServerService extends SyncServiceBase {
7070
this.app_user_id = uuid;
7171
}
7272
console.log("[SERVER] sync data");
73-
const contact_fields = this.localStorageService.getAll();
73+
const all_contact_fields = this.localStorageService.getAll();
74+
const contact_fields = this.removeExcludedContactFields(all_contact_fields);
75+
7476
const dynamic_data = await this.dynamicDataService.getState();
7577

7678
// apply temp timestamp to contact fields to sync as latest
@@ -115,6 +117,15 @@ export class ServerService extends SyncServiceBase {
115117
});
116118
}
117119

120+
/** Remove any protected fields that should not be synced */
121+
private removeExcludedContactFields(contactFields: {}) {
122+
const { prefix } = this.localStorageService;
123+
EXCLUDED_FIELDS.forEach(
124+
(field) => delete contactFields[`${prefix}.${getProtectedFieldName(field)}`]
125+
);
126+
return contactFields;
127+
}
128+
118129
private handleError(error: HttpErrorResponse) {
119130
// sync failed, retry later (?)
120131
return throwError("Could not connect to server");

0 commit comments

Comments
 (0)