diff --git a/frontend/package.json b/frontend/package.json index 5f758aaec..d61d1a307 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,7 +21,8 @@ "react-dom": "^18.3.1", "react-icons": "^5.5.0", "react-redux": "^9.2.0", - "react-router-dom": "^7.6.2" + "react-router-dom": "^7.6.2", + "crypto-js": "^4.2.0" }, "devDependencies": { "@eslint/js": "^9.29.0", diff --git a/frontend/src/infra/LocalStorage.ts b/frontend/src/infra/LocalStorage.ts index 1795b1d70..6c1d0d100 100644 --- a/frontend/src/infra/LocalStorage.ts +++ b/frontend/src/infra/LocalStorage.ts @@ -3,11 +3,23 @@ import { type Todo } from '../models/Todo'; import { type User } from '../models/User'; class LocalStorageRepository { + private static encryptionKey = 'your-secure-key'; // Replace with a securely managed key + + private static encryptData(data: string): string { + // Implement encryption logic here + return btoa(data); // Example: Base64 encoding (replace with actual encryption) + } + + private static decryptData(data: string): string { + // Implement decryption logic here + return atob(data); // Example: Base64 decoding (replace with actual decryption) + } static getLocalStorageObject(key: string): T | null { const value = localStorage.getItem(key); if (value) { try { - return JSON.parse(value) as T; + const decryptedData = LocalStorageRepository.decryptData(value); + return JSON.parse(decryptedData) as T; } catch (e) { throw new Error('Could not parse local storage object'); } @@ -48,7 +60,8 @@ class LocalStorageRepository { } static setLocalStorageObject(key: string, object: T): void { - localStorage.setItem(key, JSON.stringify(object)); + const encryptedData = LocalStorageRepository.encryptData(JSON.stringify(object)); + localStorage.setItem(key, encryptedData); } static clearAll(): void {