Skip to content

Does not decode the encoded String stored in Localstorage #34

Description

@RayyanNafees

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions