I use crypto-js for encrypt and decrypt some value but it's work fine on dev mode. I call function for encrypt on client component (after click button) and then decrypt in server component which value decrypt as a route params. I got error TypeError: Cannot read properties of undefined (reading 'parse') only on production mode. I'm not sure, I do something wrong.
import * as CryptoJS from "crypto-js";
const key = CryptoJS.enc.Utf8.parse(
process.env.NEXT_PUBLIC_CRYPTO_JS_KEY
);
const iv = CryptoJS.enc.Utf8.parse(process.env.NEXT_PUBLIC_CRYPTO_JS_IV);
const aesEncryption = (data: string) => {
try {
const encrypted = CryptoJS.AES.encrypt(data, key, { iv });
return encrypted.toString();
} catch (error) {
console.error(error);
return "";
}
};
const aesDecryption = (encryptedCode: string) => {
try {
const bytes = CryptoJS.AES.decrypt(encryptedCode, key, { iv });
return bytes.toString(CryptoJS.enc.Utf8);
} catch (error) {
console.error(error);
return "";
}
};
I use crypto-js for encrypt and decrypt some value but it's work fine on dev mode. I call function for encrypt on client component (after click button) and then decrypt in server component which value decrypt as a route params. I got error TypeError: Cannot read properties of undefined (reading 'parse') only on production mode. I'm not sure, I do something wrong.