iosreact-nativereact-native-config

How to fix JSON value '<null>' of type NSNull cannot be converted to NSString in iOS react-native-config and AsyncStorage?


I'm having problems with react native config and AsyncStorage, where null data from .env is not readable on iOS,

below is my code:

  _authAsync = async () => {
    const userToken = await syncStorageA.getItem(Config.ACCESS_TOKEN)
    this.props.navigation.navigate(userToken ? 'App' : 'Auth')
  }

Please help.

I'm having this problem only on the iOS platform on Android is working fine.


Solution

  • It seems you whenever you are setting the value to SyncStorage/AsyncStorage you are storing null value inside your storage. Rathe then storing it directly as in your case having chances of getting access token as null. check if the value exists or not.

    might below snippet helps you

    function set(key, value) {
      value = JSON.stringify(value)
      if (value) return AsyncStorage.setItem(key, value)
      else console.log('not set, stringify failed:', key, value)
    }