@@ -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,8 +27,22 @@ 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 } ) ;
30- if ( response . type == 'error' ) {
45+ if ( response . type === 'error' ) {
3146 throw new Error ( errorsLogs . login ) ;
3247 }
3348
@@ -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 , {
@@ -51,10 +68,15 @@ abstract class LoginModule extends ReportModule implements LoginModuleInterface
5168 let validSession = false ;
5269 if ( token || this . token ) {
5370 try {
54- validSession = ! ! ( await checkSession ( {
71+ const sessionResponse = await checkSession ( {
5572 baseURL : this . baseURL ,
5673 sessionToken : token || this . token ,
57- } ) ) ;
74+ } ) ;
75+ if ( sessionResponse . type === 'error' ) {
76+ validSession = false ;
77+ } else {
78+ validSession = sessionResponse . value ;
79+ }
5880 } catch ( err ) {
5981 await this . processError ( err , {
6082 message : errorsLogs . loginStatus ,
0 commit comments