Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'setGenericPasswordForOptions' of null #591

Open
agieocean opened this issue Mar 18, 2023 · 15 comments
Open

Comments

@agieocean
Copy link

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);
        });
      });
    });
  }
@alexmehta
Copy link

Did you find a solution to this issue, I have the same problem.

@dannywamuya
Copy link

I have a similar problem while trying to use setGenericPassword. Would highly appreciate any help with this if anyone was able to resolve it.

Expected behavior is to be able to store the tokens and retrieve using await Keychain.getGenericPassword();

I however encounter the following error while trying to set:

Cannot read property 'setGenericPasswordForOptions' of null

and

Keychain Error: Cannot read property 'getGenericPasswordForOptions' of null

while trying to get.

const onLogin = async () => {
  setLoading(true);
  axios
    .post(`/login`, {
	email,
	password,
    })
    .then(async (res) => {
	const { accessToken, refreshToken } = res.data;
	setAuthState({ accessToken, refreshToken, authenticated: true });

	Keychain.setGenericPassword(
            'token',
	    JSON.stringify({ accessToken, refreshToken })
	)
	.then((value) => console.log(value))
	.catch((e) => console.error(e));
	})
    .catch((err: AxiosError) => {
	Alert.alert('Login Failed', 'Something went wrong');
    })
    .finally(() => {
	setLoading(false);
    });
};

@welschmoor
Copy link

Same

@TranQuyenSinh
Copy link

Same error

@ferrariRoma
Copy link

same error. tragic 🥶
"react-native": "0.72.6",
"react-native-keychain": "^8.1.2",

@dannywamuya
Copy link

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

@ferrariRoma
Copy link

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

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 :)

@GabrielMerigo
Copy link

I had the same issue... I just deleted node_modules and installed it again :)

yarn -> 1.22.09
---
"react-native": "0.72.7
"react-native-keychain": "^8.1.2"

@katdivyareddy10
Copy link

You can try reinstalling pods and verify podfile.lock contains a link to react-native-keychain nodemodule
Screenshot 2024-02-18 at 11 13 30 AM

@Khalid-Badawi2001
Copy link

same issue, non of the solutions above worked

@micheci
Copy link

micheci commented Sep 22, 2024

yea same here, I was using expo and made the switch to secureStore. Would recommend!

@brytoz
Copy link

brytoz commented Nov 11, 2024

Had same issue...
(for IOS) make sure you add keychain manually in xcode at the 'capabilities' section and run pod install in the ios folder after installing the package. rebuild your project and it should work. you might experience crash in the app after saving the first time, but make sure your app allows and accepts keychain.

@bohnerjosh
Copy link

bohnerjosh commented Nov 14, 2024

same issue, non of the solutions above worked. Works fine on iOS but not on Android. I am not using expo. Uninstalling the app and re-building did not fix the issue

"react-native": "^0.73.9",
"react-native-keychain": "^9.2.2",

@NJneeraj
Copy link

I had the same issue.I uninstalled the app and then build it again.The error got resolved after the new build.

@bohnerjosh
Copy link

bohnerjosh commented Nov 25, 2024

Some more context for my issue: I am not using expo. This also does not happen on iOS. When I run my app initially, react native keychain works fine. However, if I close the app and re-open it again, I get this error when calling setGenericPassword and getGenericPassword.

Tried replicating in a bare react native app and was unable to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests