似乎在react-native中使用redux-persist的encrypt选项存在问题:
https://github.com/maxdeviant/redux-persist-transform-encrypt/issues/15
任何人都可以帮助解决任何解决方案/解决方法使用redux persist来加密并在react-native中存储登录令牌吗?
当我尝试使用redux persist和redux-persist-transform-encrypt时,我得 Redux-persist-transform-encrypt: expected outbound state to be a string error
import { createStore, compose, applyMiddleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import { persistStore, autoRehydrate } from 'redux-persist';
import { AsyncStorage } from 'react-native';
import createEncryptor from 'redux-persist-transform-encrypt';
import reducers from './reducers';
const store = createStore(
reducers,
{},
compose(
applyMiddleware(ReduxThunk),
autoRehydrate(),
),
);
const encryptor = createEncryptor({
secretKey: 'my-super-secret-key-999',
});
persistStore(
store,
{
storage: AsyncStorage,
whitelist: ['auth'],
transforms: [encryptor],
},
);
export default store;
我的身份验证状态是这样的:
const INITIAL_STATE = {
user: null,
token: ''
};
在使用redux persist时,有没有使用redux-persist-transform加密或转换和其他包加密令牌的解决方案?
2 回答
我找到了一个使用customTransform而不是redux-persist-transform-encrypt的解决方案:
当使用redux-persist初始状态在再水化完成之前被触发,所以我也必须应用它:
https://github.com/rt2zz/redux-persist/blob/master/docs/recipes.md#delay-render-until-rehydration-complete
这对我有用: