Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active June 21, 2017 04:17
Show Gist options
  • Save ajcrites/8af11780795f49f6330de5c33aef53ef to your computer and use it in GitHub Desktop.
Save ajcrites/8af11780795f49f6330de5c33aef53ef to your computer and use it in GitHub Desktop.
async storeAccountInfo(username, password) {
await storage.ready();
await storage.set('username', username);
const cleanup = [];
if ((await touchId.encrypt()).withFingerprint) {
const [, secureStorage] = await Promise.all([
storage.set('usingTouchId', true),
secureStorage = await secureStorageFactory.create(),
]);
await secureStorage.set('password', password);
cleanup.push(secureStorage.close())
}
cleanup.push(storage.close());
await Promise.all(cleanup);
}
storeAccountInfo(username, password) {
const cleanup = [];
let secureStorage;
return storage.ready()
.then(() => storage.set('username', username))
.then(() => touchId.encrypt())
.then(touchIdResponse => {
if (touchIdResponse.withFingerprint) {
return Promise.all([
storage.set('usingTouchId', true),
secureStorageFactory.create(),
]).then([, _secureStorage]) => {
secureStorage = _secureStorage;
return secureStorage.set('password', password);
}).then(() => {
cleanup.push(secureStorage.close());
})
}
})
.then(() => {
cleanup.push(storage.close());
return Promise.all(cleanup);
})
// the other example has no `return`, so this promise chain should
// return nothing to be consistent
.then(() => {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment