Cannot Encryption localStorage key
bobwatcherx opened this issue · comments
bobwatcherx commented
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 commented
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() })