Created
June 18, 2018 16:32
-
-
Save patrickkempff/86f44f017568a973f5c041b205e4365c to your computer and use it in GitHub Desktop.
redux-persist react-native-keychain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AsyncStorage } from 'react-native' | |
import { setGenericPassword, getGenericPassword, resetGenericPassword } from 'react-native-keychain' | |
export default { | |
async getAllKeys (callback) { | |
try { | |
const keys = await AsyncStorage.getAllKeys() | |
if (callback) { | |
callback(null, keys) | |
} | |
return keys | |
} catch (error) { | |
callback(error) | |
throw error | |
} | |
}, | |
async getItem (key, callback) { | |
try { | |
const { password } = await getGenericPassword(key) || null | |
if (callback) { | |
callback(null, password) | |
} | |
return password | |
} catch (error) { | |
if (callback) { | |
callback(error) | |
} | |
throw error | |
} | |
}, | |
async setItem (key, value, callback) { | |
try { | |
await Promise.all([ | |
AsyncStorage.setItem(key, key), | |
setGenericPassword('user', value, key) | |
]) | |
await setGenericPassword('user', value, key) | |
if (callback) { | |
callback(null) | |
} | |
} catch (error) { | |
if (callback) { | |
callback(error) | |
} | |
throw error | |
} | |
}, | |
async removeItem (key, callback) { | |
try { | |
await Promise.all([ | |
AsyncStorage.removeItem(key), | |
resetGenericPassword(key) | |
]) | |
if (callback) { | |
callback(null) | |
} | |
} catch (error) { | |
if (callback) { | |
callback(error) | |
} | |
throw error | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
usage: | |
storeConfig: { | |
// ... | |
storage: KeychainStorage, | |
// ... | |
} |
@jonathanpalma There are no errors in the logs. The bug is on Android 9 or older versions when trying to rehydrate data with size ~200kB
I've checked that other people are having this issue as well:
oblador/react-native-keychain#184
oblador/react-native-keychain#208
Have you hit this so far?
@deyanskiq got it! No, sorry I have never had this issue before. However, I would suggest you use redux-persist whitelist/blacklist or nested persist in order to persist only the sensitive information inside the Keychain (just in case you haven't tried this already). I hope I could help. Please let me know if you find a solution
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@deyanskiq is there any error logs that you can provide?