Skip to content

Commit

Permalink
Merge pull request #636 from credebl/componenets-dependency-issues
Browse files Browse the repository at this point in the history
fix: Malformed UTF-8 data error
  • Loading branch information
vivekayanworks authored Mar 27, 2024
2 parents c3fa405 + 13d93fb commit e36f4f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
26 changes: 14 additions & 12 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,29 +229,31 @@ export const encryptData = (value: any): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`

try {
const encJson: string = CryptoJS.AES.encrypt(JSON.stringify(value), CRYPTO_PRIVATE_KEY).toString();
let encData = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(encJson))

return encData;
if (typeof (value) !== 'string') {
value = JSON.stringify(value)
}
return CryptoJS.AES.encrypt(value, CRYPTO_PRIVATE_KEY).toString();
} catch (error) {
// Handle encryption error
console.error('Encryption error:', error);
return '';
}
}

const parsedData = (value: any) => {
try {
return JSON.parse(value.toString(CryptoJS.enc.Utf8));
} catch (error) {
return value.toString(CryptoJS.enc.Utf8);
}
}

export const decryptData = (value: any): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`

try {

let decData = CryptoJS.enc.Base64.parse(value).toString(CryptoJS.enc.Utf8)
let bytes = CryptoJS.AES.decrypt(decData, CRYPTO_PRIVATE_KEY).toString(CryptoJS.enc.Utf8)
const parsedData = JSON.parse(bytes);
if (typeof parsedData !== 'string') {
return JSON.stringify(parsedData);
}
return parsedData;
let bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY);
return parsedData(bytes);
} catch (error) {
// Handle decryption error or invalid input
console.error('Decryption error:', error);
Expand Down
12 changes: 5 additions & 7 deletions src/components/Authentication/SignInUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ const SignInUser = () => {

const saveEmail = async (values: emailValue) => {
setEmail(values);
await removeFromLocalStorage(storageKeys.TOKEN)
await removeFromLocalStorage(storageKeys.USER_EMAIL)
await removeFromLocalStorage(storageKeys.ORG_ID)
await removeFromLocalStorage(storageKeys.ORG_ROLES)
await removeFromLocalStorage(storageKeys.ECOSYSTEM_ID)
await removeFromLocalStorage(storageKeys.ECOSYSTEM_ROLE)
await removeFromLocalStorage(storageKeys.USER_PROFILE)

for await (const value of Object.values(storageKeys)){
await removeFromLocalStorage(value)
}

setCurrentComponent('password');
await setToLocalStorage(storageKeys.LOGIN_USER_EMAIL, values.email);
setIsPasskeySuccess(true);
Expand Down
12 changes: 8 additions & 4 deletions src/config/ecosystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ const getOrgId = async () => {
return id;
};

const getUserProfile = async () => {
const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE);
const userDetails = userProfile && (await JSON.parse(userProfile));
return userDetails;
export const getUserProfile = async () => {
try {
const userProfile = await getFromLocalStorage(storageKeys.USER_PROFILE);
const userDetails = userProfile && (await JSON.parse(userProfile));
return userDetails;
} catch (err) {

}
};

const checkEcosystem = async (): Promise<ICheckEcosystem> => {
Expand Down

0 comments on commit e36f4f4

Please sign in to comment.