@@ -23,7 +23,7 @@ configure app to AMAZONQ if for Amazon Q login
23
23
import { PropType , defineComponent } from ' vue'
24
24
import Login , { getReadyElementId as getLoginReadyElementId } from ' ./login.vue'
25
25
import Reauthenticate , { getReadyElementId as getReauthReadyElementId } from ' ./reauthenticate.vue'
26
- import RegionProfileSelector from ' ./regionProfileSelector.vue'
26
+ import RegionProfileSelector , { getReadyElementId as getSelectProfileReadyElementId } from ' ./regionProfileSelector.vue'
27
27
import { AuthFlowState , FeatureId } from ' ./types'
28
28
import { WebviewClientFactory } from ' ../../../webviews/client'
29
29
import { CommonAuthWebview } from ' ./backend'
@@ -69,6 +69,11 @@ export default defineComponent({
69
69
})
70
70
}
71
71
},
72
+ async updated() {
73
+ if (didLoad ) {
74
+ handleLoaded ()
75
+ }
76
+ },
72
77
methods: {
73
78
async refreshAuthState() {
74
79
await client .refreshAuthState ()
@@ -78,6 +83,9 @@ export default defineComponent({
78
83
if (this .authFlowState === ' LOGIN' ) {
79
84
;(window as any ).uiState = ' login'
80
85
;(window as any ).uiReadyElementId = getLoginReadyElementId ()
86
+ } else if (this .authFlowState === ' PENDING_PROFILE_SELECTION' ) {
87
+ ;(window as any ).uiState = ' selectProfile'
88
+ ;(window as any ).uiReadyElementId = getSelectProfileReadyElementId ()
81
89
} else if (this .authFlowState && this .authFlowState !== undefined ) {
82
90
;(window as any ).uiState = ' reauth'
83
91
;(window as any ).uiReadyElementId = getReauthReadyElementId ()
@@ -90,12 +98,14 @@ export default defineComponent({
90
98
91
99
// ---- START ---- The following handles the process of indicating the UI has loaded successfully.
92
100
// TODO: Move this in to a reusable class for other webviews, it feels a bit messy here
93
- let didSetReady = false
101
+ const didPageSetReady : { auth : boolean ; selectProfile : boolean } = { auth: false , selectProfile: false }
94
102
95
103
// Setup error handlers to report. This may not actually be able to catch certain errors that we'd expect,
96
104
// so this may have to be revisited.
97
105
window .onerror = function (message ) {
98
- if (didSetReady ) {
106
+ const uiState = (window as any ).uiState
107
+ const page: ' auth' | ' selectProfile' = uiState === ' login' || uiState === ' reauth' ? ' auth' : ' selectProfile'
108
+ if (didPageSetReady [page ]) {
99
109
return
100
110
}
101
111
@@ -104,7 +114,9 @@ window.onerror = function (message) {
104
114
document .addEventListener (
105
115
' error' ,
106
116
(e ) => {
107
- if (didSetReady ) {
117
+ const uiState = (window as any ).uiState
118
+ const page: ' auth' | ' selectProfile' = uiState === ' login' || uiState === ' reauth' ? ' auth' : ' selectProfile'
119
+ if (didPageSetReady [page ]) {
108
120
return
109
121
}
110
122
@@ -119,7 +131,9 @@ window.addEventListener('load', () => {
119
131
})
120
132
const handleLoaded = () => {
121
133
// in case some unexpected behavior triggers this flow again, skip since we already emitted for this instance
122
- if (didSetReady ) {
134
+ const uiState = (window as any ).uiState
135
+ const page: ' auth' | ' selectProfile' = uiState === ' login' || uiState === ' reauth' ? ' auth' : ' selectProfile'
136
+ if (didPageSetReady [page ]) {
123
137
return
124
138
}
125
139
@@ -131,9 +145,11 @@ const handleLoaded = () => {
131
145
setUiReady ((window as any ).uiState )
132
146
}
133
147
}
134
- const setUiReady = (state : ' login' | ' reauth' , errorMessage ? : string ) => {
148
+ const setUiReady = (state : ' login' | ' reauth' | ' selectProfile ' , errorMessage ? : string ) => {
135
149
client .setUiReady (state , errorMessage )
136
- didSetReady = true
150
+
151
+ const page = state === ' selectProfile' ? ' selectProfile' : ' auth'
152
+ didPageSetReady [page ] = true
137
153
}
138
154
// ---- END ----
139
155
</script >
0 commit comments