Archived
Merge branch 'fix/bad-redux-migration' into 'master'
🐛 Fix redux v4 to v5 migration See merge request edb/dusken-client!4
This commit is contained in:
commit
f465e42535
2 files changed
+22
-7
No files matched your search
+18
-5
@@ -3,12 +3,20 @@ import { connect } from 'react-redux';
|
||||
import { Root } from 'native-base';
|
||||
|
||||
import DuskenNavigation from './navigation';
|
||||
import { userDataSuccess } from './actions';
|
||||
import { logout as logoutAction, registerUserSuccess as registerUserSuccessAction } from './actions';
|
||||
import { migrateReduxPersistFourToFive } from './utils';
|
||||
|
||||
const DuskenContainer = ({ setUserData }) => {
|
||||
const DuskenContainer = ({ registerUserSuccess, userToken, user, logout }) => {
|
||||
useEffect(() => {
|
||||
migrateReduxPersistFourToFive(setUserData);
|
||||
async function inner() {
|
||||
await migrateReduxPersistFourToFive(registerUserSuccess);
|
||||
|
||||
// logout authenticated users without token
|
||||
if (user && !userToken) {
|
||||
logout();
|
||||
}
|
||||
}
|
||||
inner();
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -18,11 +26,16 @@ const DuskenContainer = ({ setUserData }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
userToken: state.userToken,
|
||||
user: state.user,
|
||||
});
|
||||
const mapDispatchToProps = {
|
||||
setUserData: userDataSuccess,
|
||||
registerUserSuccess: registerUserSuccessAction,
|
||||
logout: logoutAction,
|
||||
};
|
||||
|
||||
export default connect(
|
||||
null,
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(DuskenContainer);
|
||||
+4
-2
@@ -16,7 +16,7 @@ export function fetchWithTimeout(url, options, timeout = 10000) {
|
||||
]);
|
||||
}
|
||||
|
||||
export async function migrateReduxPersistFourToFive(setUserData) {
|
||||
export async function migrateReduxPersistFourToFive(registerUserSuccess) {
|
||||
const authedKey = 'reduxPersist:isAuthenticated';
|
||||
const userKey = 'reduxPersist:user';
|
||||
const userTokenKey = 'reduxPersist:userToken';
|
||||
@@ -34,9 +34,11 @@ export async function migrateReduxPersistFourToFive(setUserData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const userToken = await AsyncStorage.getItem(userTokenKey);
|
||||
console.log(userTokenKey, userToken);
|
||||
const user = await AsyncStorage.getItem(userKey);
|
||||
console.log(userKey, user, JSON.parse(user));
|
||||
setUserData(JSON.parse(user));
|
||||
registerUserSuccess({ auth_token: JSON.parse(userToken), ...JSON.parse(user) });
|
||||
await AsyncStorage.multiRemove(v4Keys);
|
||||
console.log('successfully migrated to new redux-persist');
|
||||
}
|
||||
Reference in new issue
Block a user