File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -72,21 +72,15 @@ export default class SessionService extends Service {
72
72
let { url } = await ajax ( `/api/private/session/begin` ) ;
73
73
win . location = url ;
74
74
75
- let event = await race ( [ waitForEvent ( window , 'message' ) , this . windowCloseWatcherTask . perform ( win ) ] ) ;
75
+ let event = await race ( [ this . windowEventWatcherTask . perform ( ) , this . windowCloseWatcherTask . perform ( win ) ] ) ;
76
76
if ( event . closed ) {
77
77
this . notifications . warning ( 'Login was canceled because the popup window was closed.' ) ;
78
78
return ;
79
79
}
80
80
81
81
win . close ( ) ;
82
- if ( event . origin !== window . location . origin || ! event . data ) {
83
- return ;
84
- }
85
82
86
- let { code, state } = event . data ;
87
- if ( ! code || ! state ) {
88
- return ;
89
- }
83
+ let { code, state } = event ;
90
84
91
85
let response = await fetch ( `/api/private/session/authorize?code=${ code } &state=${ state } ` ) ;
92
86
if ( ! response . ok ) {
@@ -111,6 +105,23 @@ export default class SessionService extends Service {
111
105
}
112
106
} ) ;
113
107
108
+ windowEventWatcherTask = task ( async ( ) => {
109
+ // eslint-disable-next-line no-constant-condition
110
+ while ( true ) {
111
+ let event = await waitForEvent ( window , 'message' ) ;
112
+ if ( event . origin !== window . location . origin || ! event . data ) {
113
+ continue ;
114
+ }
115
+
116
+ let { code, state } = event . data ;
117
+ if ( ! code || ! state ) {
118
+ continue ;
119
+ }
120
+
121
+ return { code, state } ;
122
+ }
123
+ } ) ;
124
+
114
125
windowCloseWatcherTask = task ( async window => {
115
126
// eslint-disable-next-line no-constant-condition
116
127
while ( true ) {
You can’t perform that action at this time.
0 commit comments