From 8a3c009a815b1d2de01397c18dfba8e3500c93c3 Mon Sep 17 00:00:00 2001 From: bhavanakarwade Date: Thu, 5 Dec 2024 17:12:59 +0530 Subject: [PATCH] debug encrypt data function --- src/api/Auth.ts | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/api/Auth.ts b/src/api/Auth.ts index db0b4816..2c967073 100644 --- a/src/api/Auth.ts +++ b/src/api/Auth.ts @@ -283,11 +283,31 @@ export const setToLocalStorage = async (key: string, value: any) =>{ return true } -export const getFromLocalStorage = async (key: string) =>{ - const value = await localStorage.getItem(key) - const convertedValue = value ? await decryptData(value) : '' - return convertedValue -} +// export const getFromLocalStorage = async (key: string) =>{ +// const value = await localStorage.getItem(key) +// const convertedValue = value ? await decryptData(value) : '' +// return convertedValue +// } + +export const getFromLocalStorage = async (key: string) => { + try { + const encryptedValue = localStorage.getItem(key); + console.log(`Retrieved from localStorage [${key}]:`, encryptedValue); + + if (!encryptedValue) { + console.warn(`No value found in localStorage for key: ${key}`); + return null; + } + + const decryptedValue = decryptData(encryptedValue); + console.log(`Decrypted value for [${key}]:`, decryptedValue); + + return decryptedValue ? JSON.parse(decryptedValue) : null; + } catch (error) { + console.error(`Error getting localStorage [${key}]:`, error); + return null; + } +}; export const setToCookies = (cookies: AstroCookies, key: string, value: any, option: {[key: string]: any }) =>{ // If passed value is object then checked empty object