question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cant get it to work. Cannot read property 'setGenericPasswordForOptions' of undefined

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
sergioutamacommented, Feb 25, 2019

@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

0reactions
vonovakcommented, May 19, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'name') in React ...
i am getting the below error TypeError: Cannot ...
Read more >
react-native-keychain - npm
Resolves to true if an entry exists or false if it doesn't. getInternetCredentials(server, [{ authenticationPrompt }]). Will retrieve the server ...
Read more >
Fix "Cannot read properties of undefined" error #shorts
Sometimes in Javascript you might have an array of objects like this and you to need to get some of the properties of...
Read more >
can not read properties of undefined | reading state error in react
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
Read more >
unhandled promise rejection: typeerror: undefined is not an ...
permissions exports getasync and you use that directly in your code. I can't say for sure but doing a search in your IDE...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found