react-native-sensitive-info在尝试从keychain获取保存的数据时给出undefined

时间:2017-06-06 10:49:51

标签: react-native

感谢这个伟大的图书馆。     我在我的一个本机项目中使用这个库,但每当我试图将值存储在keychain中时,在iOS中返回undefined。

Here is what is my use case
1-We have an existing "Native iOS App", which is already present in AppStore to download.
2-Now my client is redeveloping the same app in React-Native, and want to provide this new app as an update to existing users.
3-So we are keeping "Bundle ID" of our new (react-native app) same as that of older app (iOS native app), with higher version number ,so that our new will be downloaded as an updated.
4-Let's suppose, an existing user is already logged in the older app, so we want to maintain this logged status , whenever user update app with newer one.
5-In older app (iOS native app), we are saving "Access Token" in keychain, so based on whether "Access Token" is present in keychain, we decide the logged in status of user
6-Now, in newer app (react-native), we have to get that same "Access Token" from keychain, so that we can decide the logged in status of user and can navigate the user to appropriate screen.

I hope that makes sense!

Now when I am using this library, and try to get "Access Token" from keychain, its returning "undefined" in iOS.

Here may be I am doing something wrong, which only you guys can figure out.
This is how I am trying to get saved "Access Token".


    SInfo.getItem("AccessToken", {}).then(value => {
     alert(value);
    console.log("access token is", value); // value1
   });

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,我弄清楚发生了什么,我敢打赌我们在同一条船上。

我正在使用react-native-sensitive-info来存储JWT,而不是像您一样简单的键,而是从化简器(redux)存储JWT,以便路径为authentication.jwt,并且我希望查询照原样,但返回undefined

经过调查,我发现getItem的密钥是指您配置商店时提供的密钥。

例如,我正在这样配置它:

const persistConfig = {
  key: 'root',
  transforms: [saveJwtOnly],
  whitelist: ['authentication'],
  storage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)

请注意key: 'root'。现在,react-native-sensitive-infopersist:为其前缀,因此,在我的情况下,getItem能够返回的唯一可用密钥是persist:root,它返回了我的JSON。存储了软件包中的authentication.jwt_persist密钥。