Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Encryption localStorage key #49

Open
bobwatcherx opened this issue Oct 24, 2021 · 1 comment
Open

Cannot Encryption localStorage key #49

bobwatcherx opened this issue Oct 24, 2021 · 1 comment

Comments

@bobwatcherx
Copy link

i want to encrypt localstorage key and value

i using encrypt-storage but not work , i reload page , the last state to defaul t again

@polemius
Copy link
Owner

You could pass Storage implementation to recoilPersist as storage, and change behavior of getItem and setItem.
For example this storage encode everything in base64 and save it in localstorage.

import { encode, decode } from 'js-base64';

const localStorageBase64 = () => {
  return {
    setItem: (key, value) => {
      localStorage.setItem(encode(key), encode(value))
    },
    getItem: (key) => {
      const a =  localStorage.getItem(encode(key))
      return decode(a || '')
    },
    clear: () => {
      localStorage.clear()
    },
  }
}

const { persistAtom } = recoilPersist({ key: 'abc1234', storage: localStorageBase64() })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants