Comments (13)
I am also facing this issue today @nrishav007 previously I am using redux-persist-transform-encrypt v5.0.1 after I updated the v5.1.0 still facing the same error in "react": "^18.1.0".
from redux-persist-transform-encrypt.
@shanulhabib @nrishav007 faced same issue in redux-persist-transform-encrypt v5.0.1.
react = v18.1.0
node = v16.20.2
from redux-persist-transform-encrypt.
@shanulhabib @hhamza-2023 I found out the issue exactly but i need some help here. The problem is caused for line number 6. its in the exports object. If you remove the exports object then it will works fine.
"exports": {
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
},
we have to do import in a different way
@maxdeviant Please help us to import properly
import {encryptTransform} from "redux-persist-transform-encrypt";
Its not working
from redux-persist-transform-encrypt.
I faced same issue some files are missing in package. To address the missing files issue in "redux-persist-transform-encrypt," we implemented a custom encryption solution. We created a file named reduxEnc.ts to encapsulate the encryption logic using the crypto-js library. This file exports an EncryptTransform function, which serves as a custom transform for use in Redux Persist.
Here's the content of reduxEnc.ts:
// reduxEnc.ts
import Aes from 'crypto-js/aes.js';
import CryptoJsCore from 'crypto-js/core.js';
import stringify from 'json-stringify-safe';
import { createTransform,Transform } from 'redux-persist';
import type { TransformConfig } from 'redux-persist/lib/createTransform';
const makeError = (message : string) => new Error(`redux-persist-transform-encrypt: ${message}`);
interface EncryptTransformConfig {
secretKey: string;
onError?: (err: Error) => void;
}
export const EncryptTransform = (config:EncryptTransformConfig, transformConfig?:TransformConfig) : Transform<any , any> => {
if (typeof config === 'undefined') {
throw makeError('No configuration provided.');
}
const { secretKey } = config;
if (!secretKey) {
throw makeError('No secret key provided.');
}
// eslint-disable-next-line no-console
const onError = typeof config.onError === 'function' ? config.onError : console.warn;
return createTransform(
(inboundState) => Aes.encrypt(stringify(inboundState), secretKey).toString(),
(outboundState) => {
if (typeof outboundState !== 'string') {
return onError(makeError('Expected outbound state to be a string.'));
}
try {
const decryptedString = Aes.decrypt(outboundState, secretKey).toString(CryptoJsCore.enc.Utf8);
if (!decryptedString) {
throw new Error('Decrypted string is empty.');
}
try {
return JSON.parse(decryptedString);
}
catch {
return onError(makeError('Failed to parse state as JSON.'));
}
}
catch {
return onError(makeError('Could not decrypt state. Please verify that you are using the correct secret key.'));
}
}, transformConfig);
};
In store.ts, we utilize the EncryptTransform to create an encryption transform for Redux Persist. We configure the persistor with this custom transform and set up the Redux store accordingly.
Here's the relevant part of store.ts:
// store.ts
import { EncryptTransform } from './reduxEnc'; // Update the path accordingly
const encryptor: any = EncryptTransform({
secretKey: process.env.REACT_APP_PERSIST_SECRET as string,
onError: function (error: any) {
console.error('Redux Persist Encryptor Error:', error);
},
});
const persistConfig = {
key: 'root',
storage,
transforms: [encryptor],
};
const persistedReducer = persistReducer(persistConfig, reducers);
export const store = configureStore({
reducer: persistedReducer,
devTools: process.env.REACT_APP_ENVIRONMENT === 'development',
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: false,
}),
});
This custom encryption solution resolves the missing files issue, providing a secure and functional Redux Persist setup for your application.
from redux-persist-transform-encrypt.
Thanks @hhamza-2023 it works for me
from redux-persist-transform-encrypt.
@shanulhabib I will update the solution if I find any except downgrade the version
from redux-persist-transform-encrypt.
@hhamza-2023 use the latest node version. in v5.0.1 there is no issue
from redux-persist-transform-encrypt.
@hhamza-2023 use the latest node version. in v5.0.1 there is no issue
did your issue resolved?
from redux-persist-transform-encrypt.
@hhamza-2023 not yet. trying
from redux-persist-transform-encrypt.
@nrishav007 Are you using ESM in your project?
from redux-persist-transform-encrypt.
@maxdeviant yes
from redux-persist-transform-encrypt.
Thanks @hhamza-2023 it works for me
You're welcome! I'm glad to hear that it worked for you
from redux-persist-transform-encrypt.
@hhamza-2023 thanks for it
from redux-persist-transform-encrypt.
Related Issues (20)
- persistor.purge() after error
- Cannot save simple text as state. HOT 2
- Add support for asynchronous encryption HOT 3
- Error: Unable to resolve module `crypto` HOT 2
- ERROR: (0, _reduxPersistTransformEncrypt.default) is not a function HOT 1
- How to update the secretKey async HOT 9
- Update Crypto-js version HOT 2
- Question: Why the Readme says that you should not generate your secret key on the client ? HOT 1
- My persist didnt encrypted HOT 7
- v4 Not working with react-native HOT 7
- Add encryption to project where users already have unencrypted data HOT 1
- Not working with react native HOT 12
- How to use .env.local variables with next js13 app directory HOT 2
- Could not run jest unit testcases on updating redux-persis-transform-encrypt package version from "3.0.1"to "5.0.0" HOT 4
- Vitest failing with message - Failed to resolve entry for package "redux-persist-transform-encrypt" HOT 3
- Critical Security Vulnerability from crypto-js HOT 1
- Failed to resolve the path HOT 3
- (Question) Need a way to decrypt the value outside the application HOT 1
- Module not found error when using version 5.1.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-persist-transform-encrypt.