diff --git a/packages/app-utils/src/components/AppBootstrap.test.tsx b/packages/app-utils/src/components/AppBootstrap.test.tsx index 835c48c11c..aa7628daaa 100644 --- a/packages/app-utils/src/components/AppBootstrap.test.tsx +++ b/packages/app-utils/src/components/AppBootstrap.test.tsx @@ -37,7 +37,6 @@ const mockChannel = { }; jest.mock('@deephaven/jsapi-components', () => ({ ...jest.requireActual('@deephaven/jsapi-components'), - RefreshTokenBootstrap: jest.fn(({ children }) => children), useBroadcastChannel: jest.fn(() => mockChannel), useBroadcastLoginListener: jest.fn(), })); diff --git a/packages/app-utils/src/components/AppBootstrap.tsx b/packages/app-utils/src/components/AppBootstrap.tsx index 3d7b1d0ed8..20b8a4a2e5 100644 --- a/packages/app-utils/src/components/AppBootstrap.tsx +++ b/packages/app-utils/src/components/AppBootstrap.tsx @@ -3,10 +3,7 @@ import { Provider } from 'react-redux'; import { store } from '@deephaven/redux'; import '@deephaven/components/scss/BaseStyleSheet.scss'; import { ClientBootstrap } from '@deephaven/jsapi-bootstrap'; -import { - RefreshTokenBootstrap, - useBroadcastLoginListener, -} from '@deephaven/jsapi-components'; +import { useBroadcastLoginListener } from '@deephaven/jsapi-components'; import { type Plugin } from '@deephaven/plugin'; import FontBootstrap from './FontBootstrap'; import PluginsBootstrap from './PluginsBootstrap'; @@ -70,17 +67,15 @@ export function AppBootstrap({ options={clientOptions} key={logoutCount} > - - - - - - {children} - - - - - + + + + + {children} + + + + diff --git a/packages/jsapi-components/src/RefreshTokenBootstrap.tsx b/packages/jsapi-components/src/RefreshTokenBootstrap.tsx deleted file mode 100644 index 36fee7eb2f..0000000000 --- a/packages/jsapi-components/src/RefreshTokenBootstrap.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import React, { useCallback, useEffect, useState } from 'react'; -import { useApi, useClient } from '@deephaven/jsapi-bootstrap'; -import useBroadcastLoginListener from './useBroadcastLoginListener'; -import { - readRefreshToken, - RefreshTokenContext, - storeRefreshToken, -} from './RefreshTokenUtils'; - -export type RefreshTokenBootstrapProps = { - /** - * The children to render wrapped with the RefreshTokenContext. - */ - children: React.ReactNode; -}; - -/** - * RefreshTokenBootstrap component. Handles storing and reading the refresh token. - */ -export function RefreshTokenBootstrap({ - children, -}: RefreshTokenBootstrapProps): JSX.Element { - const api = useApi(); - const client = useClient(); - const [token, setToken] = useState(readRefreshToken()); - - useEffect( - function listenForTokenUpdates() { - const cleanup = client.addEventListener( - api.CoreClient.EVENT_REFRESH_TOKEN_UPDATED, - (event: CustomEvent) => { - const { detail: newToken } = event; - storeRefreshToken(newToken); - setToken(newToken); - } - ); - return cleanup; - }, - [api, client, token] - ); - - const onLogin = useCallback(() => { - setToken(readRefreshToken()); - }, []); - - const onLogout = useCallback(() => { - storeRefreshToken(null); - setToken(null); - }, []); - - useBroadcastLoginListener(onLogin, onLogout); - - return ( - - {children} - - ); -} - -export default RefreshTokenBootstrap; diff --git a/packages/jsapi-components/src/RefreshTokenUtils.ts b/packages/jsapi-components/src/RefreshTokenUtils.ts deleted file mode 100644 index ae20c82c80..0000000000 --- a/packages/jsapi-components/src/RefreshTokenUtils.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { createContext } from 'react'; -import Cookies from 'js-cookie'; -import Log from '@deephaven/log'; - -export const REFRESH_TOKEN_KEY = 'io.deephaven.web.client.auth.refreshToken'; - -export type RefreshToken = { bytes: string; expiry: number }; - -export const RefreshTokenContext = createContext(null); - -const log = Log.module('RefreshTokenUtils'); - -/** - * Read the refresh token from our cookie store - * @returns RefreshToken if it exists, null otherwise - */ -export function readRefreshToken(): RefreshToken | null { - const cookieToken = Cookies.get(REFRESH_TOKEN_KEY); - try { - if (cookieToken != null) { - return JSON.parse(cookieToken); - } - } catch (e) { - log.error('Error parsing refresh token', cookieToken, e); - } - return null; -} - -/** - * Store the provided refresh token as a cookie - * @param token The refresh token to store - */ -export function storeRefreshToken(token: RefreshToken | null): void { - if (token == null) { - Cookies.remove(REFRESH_TOKEN_KEY); - return; - } - - const cookieToken = JSON.stringify({ - bytes: token.bytes, - expiry: token.expiry, - }); - const expires = new Date(token.expiry); - - Cookies.set(REFRESH_TOKEN_KEY, cookieToken, { - secure: true, - sameSite: 'strict', - expires, - }); -} diff --git a/packages/jsapi-components/src/index.ts b/packages/jsapi-components/src/index.ts index 8606285751..3efd5476d9 100644 --- a/packages/jsapi-components/src/index.ts +++ b/packages/jsapi-components/src/index.ts @@ -1,7 +1,5 @@ export * from './HookTestUtils'; export { default as TableInput } from './TableInput'; -export * from './RefreshTokenBootstrap'; -export * from './RefreshTokenUtils'; export * from './spectrum'; export * from './TableDropdown'; export { default as useBroadcastChannel } from './useBroadcastChannel';