import * as SecureStore from 'expo-secure-store'; import { Platform } from 'react-native'; type StorageType = typeof Platform.OS; type AvailableStorageType = "web"|"android"|"none"; interface useStorageFuncs { getItemAsync: (key: string) => Promise; setItemAsync: (key: string, value: string) => Promise; removeItemAsync: (key: string) => Promise; } const storages: Record = { android: { getItemAsync: async (token: string) => await SecureStore.getItemAsync(token), setItemAsync: async (token: string, value: string) => await SecureStore.setItemAsync(token, value), removeItemAsync: async (token: string) => await SecureStore.deleteItemAsync(token), }, web: { getItemAsync: async (token: string) => localStorage.getItem(token), setItemAsync: async (token: string, value: string) => localStorage.setItem(token, value), removeItemAsync: async (token: string) => localStorage.removeItem(token) }, none: { getItemAsync: async (token: string) => "not_realized", setItemAsync: async (token: string, value: string) => { }, removeItemAsync: async (token: string) => { } } } const getStorage = (type: StorageType = Platform.OS): useStorageFuncs => { if(type in storages) return storages[type as AvailableStorageType]; else return storages.none; } export default getStorage;