Commit 78ec4693 authored by Nikolai R Kristiansen's avatar Nikolai R Kristiansen

Migrate redux-persist legacy data

parent 7cc2030e
Pipeline #714 failed with stage
in 1 minute and 45 seconds
......@@ -106,7 +106,7 @@ android {
applicationId "no.neuf.chateau"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 23
versionCode 24
versionName "1.3.0"
}
splits {
......
import React from 'react';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { Root } from 'native-base';
import DuskenNavigation from './navigation';
import { userDataSuccess } from './actions';
import { migrateReduxPersistFourToFive } from './utils';
const DuskenContainer = ({ setUserData }) => {
useEffect(() => {
migrateReduxPersistFourToFive(setUserData);
});
return (
<Root>
<DuskenNavigation />
</Root>
);
};
const DuskenContainer = () => (
<Root>
<DuskenNavigation />
</Root>
);
const mapDispatchToProps = {
setUserData: userDataSuccess,
};
export default connect()(DuskenContainer);
export default connect(
null,
mapDispatchToProps
)(DuskenContainer);
/* global fetch */
import AsyncStorage from '@react-native-community/async-storage';
export function snakeToCamelCase(val) {
return val.replace(/_([a-z])/g, function(g) {
return g[1].toUpperCase();
......@@ -13,3 +15,28 @@ export function fetchWithTimeout(url, options, timeout = 10000) {
new Promise((_, reject) => setTimeout(() => reject(new Error('Fetch request timed out')), timeout)),
]);
}
export async function migrateReduxPersistFourToFive(setUserData) {
const authedKey = 'reduxPersist:isAuthenticated';
const userKey = 'reduxPersist:user';
const userTokenKey = 'reduxPersist:userToken';
const v4Keys = [authedKey, userKey, userTokenKey];
const asyncStorageKeys = await AsyncStorage.getAllKeys();
if (v4Keys.some((key) => !asyncStorageKeys.includes(key))) {
return;
}
const isAuthenticated = await AsyncStorage.getItem(authedKey);
console.log(authedKey, isAuthenticated);
if (isAuthenticated !== 'true') {
await AsyncStorage.multiRemove(v4Keys);
return;
}
const user = await AsyncStorage.getItem(userKey);
console.log(userKey, user, JSON.parse(user));
setUserData(JSON.parse(user));
await AsyncStorage.multiRemove(v4Keys);
console.log('successfully migrated to new redux-persist');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment