rn-secure-storage icon indicating copy to clipboard operation
rn-secure-storage copied to clipboard

iOS key does not exists after some days or time

Open ANIBIT14 opened this issue 4 years ago • 6 comments

Hi, the issue is that after storing a key in secure storage, after some time it seizes to exists and the get function returns key does not exists, it happens randomly but it is happening to every user on our app. Hoping that someone could explain why it may be happening.

ANIBIT14 avatar Jan 13 '21 15:01 ANIBIT14

Hi @ANIBIT14 , I'm currently using this package in all of my apps and never encountered with this issue. Do you have any idea at what intervals this problem occurs? Or have you checked the possibility of the key being set unintentionally? Maybe RNSecureStorage.set() or RNSecureStorage.remove() is working within some condition.

talut avatar Jan 14 '21 06:01 talut

Hi @talut, I am not sure about the intervals but it happens for many users, and every-time the error is key not present: - I am sharing my code for your reference, not using .remove() anywhere in code. This is the calling function :- this.getInstanceId().then((response) => { if (response) { this.get('TOKEN_OBJECT'); } else { this.props.navigation.navigate('ErrorScreen'); } }).catch(async (error) => { crashlytics().recordError(new Error(Error in getInstanceId in FirstScreen ${error})); const instanceId = await iid().get(); Config.instanceId = instanceId; this.props.navigation.navigate('MobileNumber'); });

getInstanceId = async () => { if (Platform.OS === 'android') { const instanceId = await iid().get(); Config.instanceId = instanceId; return instanceId !== null; } if (Platform.OS === 'ios') { let res = false; try { res = await RNSecureStorage.exists('iosInstanceId'); } catch (error) { res = false; crashlytics().recordError(new Error(Error in res in getInstanceId in FirstScreen ${error})); } if (res) { let instanceIdExt = null; try { const value = await RNSecureStorage.get('iosInstanceId'); if (value !== null) { Config.instanceId = value; instanceIdExt = value; } else { const instanceId = await iid().get(); Config.instanceId = instanceId; try { await RNSecureStorage.set('iosInstanceId', instanceId, { accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY }); instanceIdExt = instanceId; } catch (error) { crashlytics().recordError(new Error(Error in getInstanctId first set in FirstScreen ${error})); throw error; } } if (instanceIdExt !== null) { return true; } return false; } catch (error) { crashlytics().recordError(new Error(Error in getInstanctId get in FirstScreen ${error})); throw error; } } let instanceIdExt = null; const instanceId = await iid().get(); Config.instanceId = instanceId; try { await RNSecureStorage.set('iosInstanceId', instanceId, { accessible: ACCESSIBLE.WHEN_UNLOCKED_THIS_DEVICE_ONLY }); instanceIdExt = instanceId; } catch (error) { crashlytics().recordError(new Error(Error in getInstanctId second set in FirstScreen ${error})); throw error; } if (instanceIdExt !== null) { return true; } return false; } };

It logs error here - crashlytics().recordError(new Error(Error in getInstanceId in FirstScreen ${error})); - Non-fatal Exception: JavaScriptError Error in getInstanceId in FirstScreen Error: key does not present

Also here crashlytics().recordError(new Error(Error in getInstanctId get in FirstScreen ${error})); Non-fatal Exception: JavaScriptError Error in getInstanctId get in FirstScreen Error: key does not present

ANIBIT14 avatar Jan 14 '21 06:01 ANIBIT14

@ANIBIT14 We have experienced a similar issue and it was due to background mode. Do you, by any chance, try to access the keychain when the app is in the background?

ghost avatar Feb 01 '21 08:02 ghost

@Lifa-7 it could be happening I think when app get's notification, it initiates the bundle in background, that is one scenario I am able to think of now, if that is the root cause, is their a way to tackle it.

ANIBIT14 avatar Feb 01 '21 09:02 ANIBIT14

same issue here after reboot device???

fukemy avatar Apr 08 '22 03:04 fukemy

Hi @talut , im sure the problem in my case

I have using iPhone simulator to test my app, when 5hPm i go to home, after day, about 8 Am, i go to company, i run the app using

npm run ios

then i saw the result i get is undefined, it's cause null result each day.

async function getAuthState() {
      try {
        const authDb = await RNSecureStorage.get('authState')
        console.log('load authState success', authJson)

=> i aways got load authState success undefined. Can u double check it

fukemy avatar Jul 19 '22 03:07 fukemy