redux-persist-transform-encrypt
redux-persist-transform-encrypt copied to clipboard
How to update the secretKey async
On app load, I want to do the following:
- Check expo-secure-store async for a previous stored encryption secret key
- If it doesn't exist, create a random uuid and save it in expo-secure-store async and use it as the secret key for encryption
- If it does exist, use it as the secret key for encryption
However, because this process is async, I don't see how to export the store and persistor.
const persistConfig = {
key: 'root',
version: 2,
storage: FSStorage(),
transforms: [
encryptTransform({
secretKey: 'my-super-secret-key',
onError: function (error) {
// Handle the error.
},
}),
],
};
export const store = configureStore({
reducer: rootReducer,
enhancers: [autoRehydrate()]
});
export const persistor = persistStore(store, persistConfig);
Does anyone have an example of how to update the secretKey after the app has loaded, without hard-coding it?
hi, I have similar problem, I want to follow the recommendation for long-term persistence, but I am not sure how to set/change the secret key.
It seems the example configuration runs when the store is initialized, and I can't see a later point where I can change that.
If this could be added to the readme, that would be super useful.
Thanks
@rueiwoqp I have the exact same problem at the moment as you described. What did you do to solve this?
Would be very useful to hear.
Thanks
@rueiwoqp @gczene @andreaslydemann I've managed to do this. I think I will provide a more detailed example soon but for the moment, here are the guidelines:
- Make your configureStore function async
- Do not render the Provider until store creation is finished by putting the configureStore method in a useEffet at the root of your app.
@ou2s +1 interested in this example!
@ou2s can you provide the example for this asap.
Sorry for the late response. I ended up using another library because my code did not work as intended.
I have the same question. The documentation recommends I should not generate or hard-code the secret key on the client side but does not show any example of how can I set/update the key after obtaining it from the server. Any solution for this? Thanks!
I have the same question. The documentation recommends I should not generate or hard-code the secret key on the client side but does not show any example of how can I set/update the key after obtaining it from the server. Any solution for this? Thanks!
You can store the key in your .env file
@ali-taghipour Thanks! That is definitelly a better approach then hard-coding the key. However this would only prevent to have the secret key in the code base not in the JS code itself. I guess that in order to avoid exposing the key in browser it needs to be dynamic, coming from the server in the runtime, which must be async.