Skip to content

Commit

Permalink
feat: refactor auth to use async await
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Oct 9, 2019
1 parent c2b3b82 commit 6d1deba
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/cli/commands/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,17 @@ async function webAuth(via: AuthCliCommands) {

const lbl = 'Waiting...';

return (
spinner(lbl)
.then(() => {
setTimeout(() => {
open(urlStr, { wait: false });
}, 2000);
// start checking the token immediately in case they've already
// opened the url manually
return testAuthComplete(token);
})
// clear spinnger in case of success or failure
.then(spinner.clear(lbl))
.catch((error) => {
spinner.clear<void>(lbl)();
throw error;
})
);
try {
await spinner(lbl);
await setTimeout(() => {
open(urlStr, { wait: false });
}, 2000);

const res = await testAuthComplete(token);
return res;
} finally {
spinner.clear<void>(lbl)();
}
}

async function testAuthComplete(token: string): Promise<{ res; body }> {
Expand Down

0 comments on commit 6d1deba

Please sign in to comment.