UNPKG

maxleap-react-native

Version:
91 lines (77 loc) 1.62 kB
import React, { AsyncStorage, NativeModules } from "react-native"; var _ = require('underscore'); const MaxLeap = NativeModules.MaxLeapCore; export function saveCurrentUser(json) { data = JSON.parse(json); delete data._id; data['sessionToken'] = data['_sessionToken']; delete data['_sessionToken']; delete data['_ClientVersion']; data['installationIds'] = [data['_installationId']]; delete data['installationIds']; MaxLeap.saveCurrentUser(JSON.stringify(data)); } export function getCurrentUser() { try { return MaxLeap.getCurrentUser().then(str => { if (!str)return null; var json = JSON.parse(str); json['_id'] = json['objectId']; json['_sessionToken'] = json['sessionToken']; delete json['sessionToken']; return JSON.stringify(json); }); } catch (e) { return null; } } export function clearUser() { try { return MaxLeap.logOut(); } catch (e) { } } export function saveCurrentInstallation(json) { try { MaxLeap.saveCurrentInstallation(JSON.stringify(data)); } catch (e) { } } export function getCurrentInstallation() { try { return MaxLeap.getCurrentInstallation(); } catch (e) { return null; } } async function save(key, json) { try { return await AsyncStorage.setItem(key, json); } catch (e) { throw e; } } async function load(key) { try { return await AsyncStorage.getItem(key); } catch (e) { throw e; } } async function remove(key) { try { return await AsyncStorage.removeItem(key); } catch (e) { throw e; } } async function clear(keys) { try { return await AsyncStorage.multiRemove(keys); } catch (e) { throw e; } }