diff --git a/codex-vscode/src/services/oauth.service.ts b/codex-vscode/src/services/oauth.service.ts index a1e1e68a..72648dfb 100644 --- a/codex-vscode/src/services/oauth.service.ts +++ b/codex-vscode/src/services/oauth.service.ts @@ -31,11 +31,14 @@ export class OAuthService implements IOAuthService { ); } + // The Promise.race method is used here to race two promises against each other: + // 1. OAuthService.codeExchangePromise.promise - This promise resolves when the user completes the authorization process. + // 2. A timeout promise that rejects after 60 seconds, indicating the user did not complete the login in time. + // The first promise to settle (either resolve or reject) will determine the outcome of the authenticate method. return Promise.race([ OAuthService.codeExchangePromise.promise, new Promise((_, reject) => setTimeout(() => { - // TODO we should make this alot simpler this.clearCodeExchangePromise(); reject({ errorType: "cancelled", @@ -46,6 +49,7 @@ export class OAuthService implements IOAuthService { ]); } + // postAuthorization returns a function that is called from the promiseFromEvent function when the event is fired private postAuthorization: () => PromiseAdapter = () =>