我正在使用'react-native-secure-key-store'npm软件包将会话密钥安全地存储在React native中。 https://www.npmjs.com/package/react-native-secure-key-store
当我尝试保存时,出现以下错误
TypeError: Cannot read property 'set' of undefined
TypeError: Cannot read property 'set' of undefined
at Login._this.saveSessionToken (blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:81379:45)
at blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:81370:17
at tryCallOne (blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:16056:14)
at blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:16157:17
at blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:2884:21
at _callTimer (blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:2773:9)
at _callImmediatesPass (blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:2809:9)
at Object.callImmediates (blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:3028:14)
at MessageQueue.__callImmediates (blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:2362:18)
at blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:2189:18
at blob:http://localhost:8081/5eb8f7f3-851b-47b3-8b90-107d6700bef3:2189:18
我遵循了文档,并创建了一个如下所示的secureKeyStore.js文件。
secureKeyStore.JS
import RNSecureKeyStore from 'react-native-secure-key-store';
export function storeKey ( key, value ){
RNSecureKeyStore.set(key, value)
.then((res) => {
console.log(res);
}, (err) => {
console.log(err);
});
}
export function retrieveKey(key) {
RNSecureKeyStore.get(key)
.then((res) => {
console.log(res);
}, (err) => {
console.log(err);
});
}
export function removeKey(key) {
RNSecureKeyStore.remove(key)
.then((res) => {
console.log(res);
}, (err) => {
console.log(err);
});
}
这就是我访问这些方法的方式。
Login.JS
import { storeKey, retrieveKey } from '../../../utils/secureKeyStore';
storeKey('sessionToken', 'xyz');
package.json-依赖项
"react-native-secure-key-store": "^1.0.9",
您能建议我在哪里做错了吗
谢谢 R
答案 0 :(得分:0)
同样的问题!这是我尝试的方式:
yarn
命令安装的。请改用npm
。可能是毛线错误。1.0.5
react-native link xxxxx
。ios/build
文件夹。react-native run-ios
。答案 1 :(得分:0)
您需要在执行JSON.stringfy之后保存数据,并获取需要执行JSON.parse的数据。