I used to develop in android previously and i used to used SharePreference for storing user tokens. Is there anything such available in react native for both ios and android? >
If you're using create-react-native-app
or exp
, you can use Expo.SecureStore
to store your token.
import {SecureStore} from 'expo';
await SecureStore.setItemAsync('secure_token','sahdkfjaskdflas$%^&');
const token = await SecureStore.getItemAsync('secure_token');
console.log(token); // output: sahdkfjaskdflas$%^&
Details: https://docs.expo.io/versions/latest/sdk/securestore
Update in Dec 2020:
The SecureStore module is now become expo-secure-store
import * as SecureStore from 'expo-secure-store';
await SecureStore.setItemAsync('secure_token','sahdkfjaskdflas$%^&');
const token = await SecureStore.getItemAsync('secure_token');
console.log(token); // output: sahdkfjaskdflas$%^&