betodealmeida commented on code in PR #40097:
URL: https://github.com/apache/superset/pull/40097#discussion_r3269664523
##########
superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.tsx:
##########
@@ -107,43 +100,50 @@ export function OAuth2RedirectMessage({
const dispatch = useDispatch();
useEffect(() => {
- /* Listen for messages from the OAuth2 tab.
- *
- * After OAuth2 is successful the opened tab will send a message before
- * closing itself. Once we receive the message we can retrigger the
- * original query in SQL Lab, explore, or in a dashboard.
- */
- const redirectUrl = new URL(extra.redirect_uri);
- const handleMessage = (event: MessageEvent) => {
- if (
- event.origin === redirectUrl.origin &&
- event.data.tabId === extra.tab_id &&
- event.source === oAuthTab.current
- ) {
- if (source === 'sqllab' && query) {
- dispatch(reRunQuery(query));
- } else if (source === 'explore' && chartId) {
- dispatch(triggerQuery(true, chartId));
- } else if (source === 'dashboard') {
- dispatch(onRefresh(chartList.map(Number), true, 0, dashboardId));
- }
+ const handleOAuthComplete = (tabId?: string) => {
+ if (tabId !== extra.tab_id) {
+ return;
+ }
+ if (source === 'sqllab' && query) {
+ dispatch(reRunQuery(query));
+ } else if (source === 'explore' && chartId) {
+ dispatch(triggerQuery(true, chartId));
+ } else if (source === 'dashboard') {
+ dispatch(onRefresh(chartList.map(Number), true, 0, dashboardId));
}
};
- window.addEventListener('message', handleMessage);
+
+ const channel =
+ typeof BroadcastChannel !== 'undefined'
+ ? new BroadcastChannel(OAUTH_CHANNEL_NAME)
+ : null;
+
+ if (channel) {
+ channel.onmessage = event => {
+ handleOAuthComplete(event.data?.tabId);
+ };
+ }
+
+ const handleStorage = (event: StorageEvent) => {
+ if (event.key !== OAUTH_STORAGE_EVENT_KEY || !event.newValue) {
+ return;
+ }
+
+ try {
+ const message = JSON.parse(event.newValue) as { tabId?: string };
+ handleOAuthComplete(message.tabId);
+ } catch {
Review Comment:
Sorry, I missed this and merged before implementing. Will follow up with the
fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]