react-native-keychain: TypeError: Cannot read property 'setGenericPasswordForOptions' of null
Version:
"react-native-keychain": "^8.1.1"
"react-native": "0.71.3"
Expected behavior:
Set token, get token, display token
Actual behavior:
WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'setGenericPasswordForOptions' of null
Relevant code:
const onSubmit = data => {
let URL = "http://192.168.1.121:8000/api/token/";
let config = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}
data = {
'username': data.UserName,
'password': data.Password
}
axios.post(URL, data, config).then(response => {
credentialsKey = data.UserName;
Keychain.setGenericPassword(credentialsKey, response.data.access, { service: credentialsKey }).then(() => {
Keychain.getGenericPassword({ service: credentialsKey }).then(response => {
alert(response);
});
});
});
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 4
- Comments: 19
Hey, I managed to solve my problem. It was an oversight, I realized I can’t user react-native-keychain in expo. So incase you are using expo, you could opt for SecureStore
Same
In my case, i simply closed the terminal and did
npx react-native run-androidand it fixed the issue. I guess android studio needed some dependenciesmy problem is resolved, react-native-keychain clashes with react-native-gesture-handle. I installed “react-native-gesture-handler”: “^2.24.0”, and the problem was solved
I had the same issue.I uninstalled the app and then build it again.The error got resolved after the new build.
You can try reinstalling pods and verify podfile.lock contains a link to react-native-keychain nodemodule
I just read @dannywamuya’s comment after I learned expo managed workflow can’t use react-native-keychain. and I solved it using SecureStore you mentioned. thank you so much 😃
Did you find a solution to this issue, I have the same problem.