I used crypto-js to encode & decode my data before saving via persistenAtom
Code
import { persistentAtom } from "@nanostores/persistent";
import CryptoJS from 'crypto-js'
const ENCRYPTION_KEY = 'my-secret-key'
const encrypt = (data: any):string => CryptoJS.AES.encrypt(JSON.stringify(data), ENCRYPTION_KEY).toString()
const decrypt = (encryptedData:string):any => {
const bytes = CryptoJS.AES.decrypt(encryptedData, ENCRYPTION_KEY)
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8))
}
export const counterP = persistentAtom<number>("counter", 0, {
encode: encrypt,
decode: decrypt,
});
export const add = action(counterP, "add", (store) => {
counterP.set(counterP.get() + 1);
});
Issue
Whenever i load the stored data using counterP.get() it shows me the encrypted data (not the actual data after decoding it as it was supposed to)
Resolve
decode the data stored in localStorage before loading it into the Atom Store
Would love if that custom storage issue gets resolved as described here #30
I used
crypto-jsto encode & decode my data before saving viapersistenAtomCode
Issue
Whenever i load the stored data using
counterP.get()it shows me the encrypted data (not the actual data after decoding it as it was supposed to)Resolve
decodethe data stored in localStorage before loading it into the Atom StoreWould love if that custom storage issue gets resolved as described here #30