Skip to content

Commit

Permalink
Update docs on customized storage objects (aws-amplify#1904)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricgrothues committed Jun 24, 2020
1 parent e1f15a0 commit 3d32900
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions docs/lib/auth/fragments/js/manageusers.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Here is the example of how to use AsyncStorage as your storage object which will
```javascript
import { AsyncStorage } from 'react-native';

const MEMORY_KEY_PREFIX = '@MyStorage:';
const MYSTORAGE_KEY_PREFIX = '@MyStorage:';
let dataMemory = {};

/** @class */
Expand All @@ -208,7 +208,7 @@ class MyStorage {
* This is used to set a specific item in storage
*/
static setItem(key, value) {
AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
AsyncStorage.setItem(MYSTORAGE_KEY_PREFIX + key, value);
dataMemory[key] = value;
return dataMemory[key];
}
Expand All @@ -224,7 +224,7 @@ class MyStorage {
* This is used to remove an item from storage
*/
static removeItem(key) {
AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
AsyncStorage.removeItem(MYSTORAGE_KEY_PREFIX + key);
return delete dataMemory[key];
}

Expand All @@ -237,28 +237,28 @@ class MyStorage {
}

/**
* Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
* Will sync the MyStorage data from AsyncStorage to storageWindow MyStorage
*/
static sync() {
if (!MemoryStorage.syncPromise) {
MemoryStorage.syncPromise = new Promise((res, rej) => {
if (!MyStorage.syncPromise) {
MyStorage.syncPromise = new Promise((res, rej) => {
AsyncStorage.getAllKeys((errKeys, keys) => {
if (errKeys) rej(errKeys);
const memoryKeys = keys.filter((key) => key.startsWith(MEMORY_KEY_PREFIX));
const memoryKeys = keys.filter((key) => key.startsWith(MYSTORAGE_KEY_PREFIX));
AsyncStorage.multiGet(memoryKeys, (err, stores) => {
if (err) rej(err);
stores.map((result, index, store) => {
const key = store[index][0];
const value = store[index][1];
const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
const memoryKey = key.replace(MYSTORAGE_KEY_PREFIX, '');
dataMemory[memoryKey] = value;
});
res();
});
});
});
}
return MemoryStorage.syncPromise;
return MyStorage.syncPromise;
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/lib/auth/fragments/js/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Amplify.configure({
},

// OPTIONAL - customized storage object
storage: new MyStorage(),
storage: MyStorage,

// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH',
Expand Down

0 comments on commit 3d32900

Please sign in to comment.