在反应原生中存储私有数据的最佳方式是什么?

2023-12-20

我怎样才能实现这样的功能remember me通过反应应用程序进行身份验证时?我认为未加密AsyncStorage这不是最好的方法,因为数据对用户开放。我尝试过使用realm,但陷入了在android中无法解决的问题expo测试应用程序。它说我需要编译 android 的本机代码并编辑它(在 MainApplication.js 中添加领域对象创建)。我不想在项目尚未发布时编译它。 Instagram 和其他 RN 应用程序如何存储身份验证数据?最好的方法是什么?


在反应原生中存储私有数据的最佳方式是什么?

我建议使用像这样的库反应本机钥匙串 https://github.com/oblador/react-native-keychain将私有数据存储在反应本机 https://facebook.github.io/react-native/

你可以这样使用它:

// Generic Password, service argument optional
Keychain
  .setGenericPassword(username, password)
  .then(function() {
    console.log('Credentials saved successfully!');
  });

// service argument optional
Keychain
  .getGenericPassword()
  .then(function(credentials) {
    console.log('Credentials successfully loaded for user ' + credentials.username);
  }).catch(function(error) {
    console.log('Keychain couldn\'t be accessed! Maybe no value set?', error);
  });

希望我的回答对你有帮助????

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在反应原生中存储私有数据的最佳方式是什么? 的相关文章

随机推荐