Cant get it to work. Cannot read property 'setGenericPasswordForOptions' of undefined
See original GitHub issueI have read through similar issues and re-building (even with reset cache) does not seem to work. Any ideas on where to look?
I think this looks like Issue 84 but not sure how it was solved. As RNKeychainManager is undefined in index.js of the component react-native-keychain. Here is how I came to that realization:
RN version is 57 Keychain v: 3
I used the latest react-native-keychain through npm install --save. and double checked on the manual installation all links exist, in the gradle and mainactivity files.
Here is my example:
import * as Keychain from 'react-native-keychain';
class demo extends Component {
componentWillMount() {
console.log(keychain)
try {
Keychain.setGenericPassword(
{'key1':'test'}
).then(function(){
console.log("all clear....set the credentials")
}).catch(function(error) {
console.warn('Keychain couldn\'t be set!', error);
});;
} catch (err) {
console.log("error persisting tokens", err)
}
}
async load() {
try {
const credentials = await Keychain.getGenericPassword();
if (credentials) {
console.log("credentials are ", credentials)
this.props.setTokens(tokens);
} else {
console.log("could not load credentials", credentials)
}
}
catch (err) {
console.log("error getting credentials", err)
}
};
… rest of the class
when I console.log Keychain on componentWillMount I see all the methods in it. So I am guessing it is not a link problem?
Here is the output of console.log(keychain): Keychain {canImplyAuthentication: ƒ, getSupportedBiometryType: ƒ, setInternetCredentials: ƒ, getInternetCredentials: ƒ, resetInternetCredentials: ƒ, …}
When I call either getGenericPassword…or setGenericPassword I get Cannot read property ‘setGenericPasswordForOptions’ of undefined
If it is worth noting: when I try to debug index.js of the moduie:
export function setGenericPassword(
username: string,
password: string,
serviceOrOptions?: string | Options
): Promise {
console.log("hello", username, password, serviceOrOptions);
return RNKeychainManager.setGenericPasswordForOptions(
getOptionsArgument(serviceOrOptions),
username,
password
);
}
the function is actually hit and console.log prints the passed parameters in my case ‘test1’. The issue is in the return that follows. What do you recon I am doing wrong?
Issue Analytics
- State:
- Created 5 years ago
- Comments:15
Top GitHub Comments
@tirsoh @ibrahimokdadov just curious wether you guys already have cocoapods set before using this library. If cocoapods already installed, there is additional step that need to be done which is to run
pod install
hi! There is a problem with how the project is linked. Please open a new issue with a minimal runnable repro (https://stackoverflow.com/help/reprex) so we can fix it.