Last active
June 21, 2017 04:17
-
-
Save ajcrites/8af11780795f49f6330de5c33aef53ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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