SecureAsyncStorage Module

SecureAsyncStorage is a simple, encrypted, asynchronous, persistent, key-value storage system that is global to the app. It should be used instead of AsyncStorage to store sensitive data.

The following methods are supported with the SecureAsyncStorage module:

Example

import { NativeModules } from 'react-native';
import {
  AppRegistry,
  Button,
  FlatList,
  StyleSheet,
  Text,
  View
} from '@react-native';
import { SecureAsyncStorage } from '@youi/react-native-youi';

Methods

getItem

Fetches an item for a key and invokes a callback upon completion.

Definition:

getItem: function(key: string, callback?: ?(error: ?Error, result: ?string) => void)

Parameters:

Name Type Required Description
key string Yes Key of the item to fetch.
callback ?(error: ?Error, result: ?string) => void No Function that will be called with a result if found or any error.

setItem

Sets the value for a keyand invokes a callback upon completion. Returns a promise object.

Definition:

setItem: function(key: string, value: string, callback?: ?(error: ?Error) => void)

Parameters:

Name Type Required Description
key string Yes Key of the item to fetch.
value string Yes Value set for the key.
callback ?(error: ?Error) => void No Function that will be called with any error.

removeItem

Removes an item for a keyand invokes a callback upon completion. Returns a Promise object.

Definition:

removeItem: function(key: string, callback?: ?(error: ?Error) => void)

Parameters:

Name Type Required Description
key string Yes Key of the item to fetch.
callback ?(error: ?Error) => void No Function that will be called with any error.

mergeItem

Merges an existing key value with an input value, assuming both values are stringified JSON. Returns a Promise object.

Definition:

mergeItem: function(key: string, value: string, callback?: ?(error: ?Error) => void)

Parameters:

Name Type Required Description
key string Yes Key of the item to modify.
value string Yes New value to merge for the key.
callback ?(error: ?Error) => void No Function that will be called with any error.

Clear

Erases all SecureAsyncStorage for all clients, libraries, etc. Returns a Promise object.

Definition:

clear: function(callback?: ?(error: ?Error) => void)

Parameters:

Name Type Required Description
callback ?(error: ?Error) => void No Function that will be called with any error.

getAllKeys

Gets all keys known to your app; for all callers, libraries, etc.

Definition:

getAllKeys: function(callback?: ?(error: ?Error, keys: ?Array<string>) => void)

Parameters:

Name Type Required Description
callback ?(error: ?Error, keys: ?Array) => void No Function that will be called the keys found and any error.

flushGetRequests

Flushes any pending requests using a single batch call to get the data.

Definition:

static flushGetRequests(): [object Object]

multiGet

This allows you to batch the fetching of items given an array of key inputs. Your callback will be invoked with an array of corresponding key-value pairs found.

Definition:

getItem: function(keys: Array<string>, callback?: ?(errors: ?Array<Error>, result: ?Array<Array<string>>) => void)

Parameters:

Name Type Required Description
key Array Yes Array of key of the item to fetch.
callback ?(errors: ?Array, result: ?Array) => void No Function that will be called with a key-value array of the results, plus an array of any key-specific errors found.

multiSet

Use this as a batch operation for storing multiple key-value pairs. When the operation completes you’ll get a single callback with any errors.

Definition:

getItem: function(keyValuePairs: Array<Array<string>>, callback?: ?(errors: ?Array<Error>) => void)

Parameters:

Name Type Required Description
keyValuePairs Array Yes Array of key-value array for the items to set.
callback ?(errors: ?Array) => void No Function that will be called with an array of any key-specific errors found.

multiRemove

Call this to batch the deletion of all keys in the keys array.

Definition:

multiRemove: function(keys: Array<string>, callback?: ?(errors: ?Array<Error>) => void)

Parameters:

Name Type Required Description
keys Array Yes Array of key for the items to delete.
callback ?(errors: ?Array) => void No Function that will be called an array of any key-specific errors found.

multiMerge

Batch operation to merge in existing and new values for a given set of keys. This assumes that the values are stringified JSON.

Definition:

getItem: function(keyValuePairs: Array<Array<string>>, callback?: ?(errors: ?Array<Error>) => void)

Parameters:

Name Type Required Description
keyValuePairs Array Yes Array of key-value array for the items to merge.
callback ?(errors: ?Array) => void No Function that will be called with an array of any key-specific errors found.