@@ -14,6 +14,7 @@ const sleep = (duration: number) => new Promise(resolve => setTimeout(resolve, d
1414
1515abstract class LoginModule extends ReportModule implements LoginModuleInterface {
1616 private pendingLogin : boolean = false ;
17+ private pendingToken = '' ;
1718
1819 async initiateLogin ( ) : Promise < void > {
1920 await this . setContext ( DEEPCODE_CONTEXT . LOGGEDIN , false ) ;
@@ -26,6 +27,20 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
2627 try {
2728 const checkCurrentToken = await this . checkSession ( ) ;
2829 if ( checkCurrentToken ) return ;
30+
31+ // In case we already created a draft token earlier, check if it's confirmed already
32+ if ( this . pendingToken ) {
33+ try {
34+ const confirmedPendingToken = await this . checkSession ( this . pendingToken ) ;
35+ if ( confirmedPendingToken ) {
36+ await this . setToken ( this . pendingToken ) ;
37+ return ;
38+ }
39+ } finally {
40+ this . pendingToken = '' ;
41+ }
42+ }
43+
2944 const response = await startSession ( { baseURL : this . baseURL , source : this . source } ) ;
3045 if ( response . type == 'error' ) {
3146 throw new Error ( errorsLogs . login ) ;
@@ -37,6 +52,8 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
3752 const confirmed = await this . waitLoginConfirmation ( sessionToken ) ;
3853 if ( confirmed ) {
3954 await this . setToken ( sessionToken ) ;
55+ } else {
56+ this . pendingToken = sessionToken ;
4057 }
4158 } catch ( err ) {
4259 await this . processError ( err , {
0 commit comments