Skip to content

Commit

Permalink
added logs for set to local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavanakarwade committed Dec 4, 2024
1 parent 248edfb commit 7e3526c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ export const decryptData = (value: any , isUserProfile?: boolean): string => {
try {
let bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY);
if(isUserProfile){
const convertedData = bytes.toString(CryptoJS.enc.Utf8)
console.log()
console.log(bytes , 'bytes........................')}
return bytes.toString(CryptoJS.enc.Utf8);
} catch (error) {
Expand All @@ -257,7 +259,7 @@ export const decryptData = (value: any , isUserProfile?: boolean): string => {
}
}

export const setToLocalStorage = async (key: string, value: any) =>{
export const setToLocalStorage = async (key: string, value: any , isUserProfile?: boolean) =>{
// If passed value is object then checked empty object
if (typeof value === 'object' && Boolean(Object.keys(value).length <= 0)) {
return;
Expand All @@ -267,8 +269,12 @@ export const setToLocalStorage = async (key: string, value: any) =>{
if (typeof value === 'string' && !value?.trim()) {
return;
}

if(isUserProfile){
console.log(value, 'in set local storage value .................................')}
const convertedValue = await encryptData(value)
if(isUserProfile){
console.log(convertedValue , 'converted value in set method ..........................')
}
const setValue = await localStorage.setItem(key, convertedValue as string)
return true
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Authentication/SignInUserPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const SignInUserPasskey = (signInUserProps: signInUserProps) => {

}
await setToLocalStorage(storageKeys.PERMISSIONS, permissionArray);
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile));
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile) , true);
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email);
return {
role: role?.orgRole || ""
Expand Down
2 changes: 1 addition & 1 deletion src/components/Authentication/SignInUserPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const SignInUserPassword = (signInUserProps: SignInUser3Props) => {
id, profileImg, firstName, email,

}
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile));
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile) , true);
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email);
return {
role: role?.orgRole ?? '',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Profile/EditUserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const EditUserProfile = ({ toggleEditProfile, userProfileInfo, updateProfile }:
}

updateProfile(userData);
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(updatedUserData));
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(updatedUserData) , true);
window.location.reload();
setLoading(false)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Profile/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const UserProfile = ({ noBreadcrumb }: { noBreadcrumb?: boolean }) => {
const userProfile = {
id, profileImg, firstName, email,
}
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile))
await setToLocalStorage(storageKeys.USER_PROFILE, JSON.stringify(userProfile) , true)
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email)
}
} catch (error) {
Expand Down

0 comments on commit 7e3526c

Please sign in to comment.