我正在学习使用 React Navigation 和用 TypeScript 编写的 GraphQL 的 React Native。我将使用 Facebook 登录让用户注册(使用 Passport.js 或 Auth0)
我如何在 React Native 中管理用户 session ?我需要使用 Redux 吗?
请赐教。
最佳答案
因为 session 通常包含敏感信息,所以我建议避免使用 AsyncStorage
或类似的解决方案。
使用更安全的方法 react-native-keychain .它将 session 存储在安全存储中。
示例代码
import * as Keychain from 'react-native-keychain';
// When you want to store the session
const rawValue = JSON.stringify(session);
await Keychain.setGenericPassword('session', rawValue);
// When you want to retrieve the session
const credential = await Keychain.getGenericPassword();
const session = JSON.parse(credential.password)
关于javascript - 如何在 React Native 中管理用户 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57776847/