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

IOS only -> Values remain stored even after app reinstall/rebuild

Open DragomirAndrei19 opened this issue 1 year ago • 0 comments

Problem: On iOS (not on Android too) the values stored at keys are persisting even after app reinstall/rebuild. Strangely enough, if I go to Simulator -> Device -> Erase All Content and Settings, the keychain seems to reset but it gets "polluted" again if I delete the app and reinstall it. This wasn't the behavior in the previous version (2.0.8).

Environment: XCode 15.2, iOS 17.2 Emulator

Project: Clean bare-bones React Native Typescript project (without expo) created using command npx react-natie init MyProject --template react-native-template-typescript

Code: App.tsx

import React, { useEffect } from 'react';
import { View } from 'react-native';
import RNSecureStorage, { ACCESSIBLE } from 'rn-secure-storage';

function App(): React.JSX.Element {

  const myFunction = () => {
    RNSecureStorage.getItem("myUniqueItem123456").then((res) => {
      console.log("Value at key is ", res);
    }).catch((err) => {
      console.log("Key doesn't exist, setting value at key now")
      RNSecureStorage.setItem("myUniqueItem123456", "my_value", { accessible: ACCESSIBLE.WHEN_UNLOCKED }).then((res) => {
        console.log("Set result is: ", res);
      }).catch((err) => {
        console.log(err);
      });
    })
  }

  useEffect(() => {
    myFunction()
  }, [])

  return (
    <View>

    </View>
  )
}

export default App;

1. First run behavior (console.logs)

Android:

LOG Running "MyTestProject1" with {"rootTag":11} LOG Key doesn't exist, setting value at key now LOG Set result is: Stored successfully

iOS:

LOG Running "MyTestProject1" with {"rootTag":1, "initialProps":{}} LOG Key doesn't exist, setting value at key now LOG Set result is: Stored successfully

2. Second run behaviour (after deleting reinstalling the application)

Android:

LOG Running "MyTestProject1" with {"rootTag":11} LOG Key doesn't exist, setting value at key now LOG Set result is: Stored successfully

iOS:

LOG Running "MyTestProject1" with {"rootTag":1, "initialProps":{}} LOG Value at key is my_value // --> value seems 'trapped' after a new fresh install

Also my package.json file

{
  "name": "MyTestProject1",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.4",
    "rn-secure-storage": "^3.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

DragomirAndrei19 avatar Feb 20 '24 16:02 DragomirAndrei19