88 SCHEMA_RESPONSE ,
99 SET_PARTIAL_AUTHENTICATION_TOKEN_FOR_PARENT ,
1010 EXPLORER_LISTENING_FOR_PARTIAL_TOKEN ,
11+ PARENT_LOGOUT_SUCCESS ,
12+ TRIGGER_LOGOUT_IN_PARENT ,
1113} from './constants' ;
1214import type { JSONValue } from '../types' ;
1315
@@ -79,6 +81,9 @@ export type OutgoingEmbedMessage =
7981 status ?: number ;
8082 headers ?: Headers ;
8183 } ;
84+ }
85+ | {
86+ name : typeof PARENT_LOGOUT_SUCCESS ;
8287 } ;
8388
8489// TODO(Maya) uncomment and switch to MessageEvent as a generic when tsdx supports Typescript V4.
@@ -101,10 +106,14 @@ export type IncomingEmbedMessage = MessageEvent;
101106// }>
102107// | MessageEvent<{
103108// name: typeof SET_PARTIAL_AUTHENTICATION_TOKEN_FOR_PARENT;
104- // key : string;
109+ // localStorageKey : string;
105110// partialToken: string;
106111// }>
107112// | MessageEvent<{
113+ // name: typeof TRIGGER_LOGOUT_IN_PARENT;
114+ // localStorageKey: string;
115+ // }>
116+ // | MessageEvent<{
108117// name: typeof EXPLORER_LISTENING_FOR_PARTIAL_TOKEN;
109118// localStorageKey?: string;
110119// }>
@@ -276,6 +285,26 @@ export const handleAuthenticationPostMessage = ({
276285 ) ;
277286 }
278287
288+ // When the embed logs out, remove the partial token in local storage
289+ if ( data . name === TRIGGER_LOGOUT_IN_PARENT ) {
290+ const partialEmbedApiKeysString = window . localStorage . getItem (
291+ 'apolloStudioEmbeddedExplorerEncodedApiKey'
292+ ) ;
293+ const partialEmbedApiKeys = partialEmbedApiKeysString
294+ ? JSON . parse ( partialEmbedApiKeysString )
295+ : { } ;
296+ delete partialEmbedApiKeys [ data . localStorageKey ] ;
297+ window . localStorage . setItem (
298+ 'apolloStudioEmbeddedExplorerEncodedApiKey' ,
299+ JSON . stringify ( partialEmbedApiKeys )
300+ ) ;
301+ sendPostMessageToEmbed ( {
302+ message : { name : PARENT_LOGOUT_SUCCESS } ,
303+ embeddedIFrameElement,
304+ embedUrl,
305+ } ) ;
306+ }
307+
279308 if (
280309 data . name === EXPLORER_LISTENING_FOR_PARTIAL_TOKEN &&
281310 data . localStorageKey
0 commit comments