Dear All,
I am working on some code at present the reason for the encryption is that I have a page open to access by anyone and do not want malitious visitors to be able to read others details should they somehow gain access to the data collections. I have created a backend module called decrypt.jsw and this is the code for decrypting the cipher of the email, I am wanting to return the data to client side once it has been decrypted but on client side code I am receiving an undefined response?
backend code:
export function decryptEmailOne() {
return decryptEmail();
}
function decryptEmail() {
return wixData.get("VeriTagsProfileData", wixUsers.currentUser.id)
.then((results) => {
let item = results;
let email = item.email
console.log(email); // Logs the encrypted email
generateKey().then(function (code) {
console.log(code); // Logs the decryption key
let key = code;
let ciphertext = email;
// Decrypt
let bytes = CryptoJS.AES.decrypt(ciphertext, 'key');
let originalText = bytes.toString(CryptoJS.enc.Utf8);
console.log(originalText); // this logs the correct details
var data = originalText;
console.log(data); // this logs the correct details//
return data; // there seems to be an issue with the return
})
})
}
client side code:
import { decryptEmailOne } from 'backend/decrypt.jsw';
export function button85_click(event) {
console.log("call to function"); // logs the action
decryptEmailOne().then(function(data) {
console.log(data); // logs undefined
})
}
Could someone help out with a little bit of code manipulation so that I get the decrypted result return to client side code?
@brainstorrrm @Yisrael (Wix) @Alexander (Wix)
any help would be greatly appreciated.
Best wishes
Si