Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow logout on open file #1744

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/app-utils/src/components/AppBootstrap.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useCallback, useMemo, useState } from 'react';
import '@deephaven/components/scss/BaseStyleSheet.scss';
import { storeCookieToken } from '@deephaven/auth-plugins';
import { ClientBootstrap } from '@deephaven/jsapi-bootstrap';
import {
RefreshTokenBootstrap,
storeRefreshToken,
useBroadcastLoginListener,
} from '@deephaven/jsapi-components';
import { type Plugin } from '@deephaven/plugin';
Expand Down Expand Up @@ -53,6 +55,8 @@ export function AppBootstrap({
const onLogin = useCallback(() => undefined, []);
const onLogout = useCallback(() => {
setLogoutCount(value => value + 1);
storeCookieToken(null);
storeRefreshToken(null);
}, []);
useBroadcastLoginListener(onLogin, onLogout);
return (
Expand Down
15 changes: 15 additions & 0 deletions packages/auth-plugins/src/AuthPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import React from 'react';
import Log from '@deephaven/log';
import Cookies from 'js-cookie';

const log = Log.module('AuthPluginPsk');

/**
* Map from auth config keys to their values
Expand Down Expand Up @@ -42,3 +46,14 @@ export function isAuthPlugin(plugin?: unknown): plugin is AuthPlugin {
typeof authPlugin.isAvailable === 'function'
);
}

export const PSK_TOKEN_KEY = 'io.deephaven.web.client.auth.psk.token';

export function storeCookieToken(token: string | null): void {
log.debug2('Storing token in cookie', token);
if (token != null) {
Cookies.set(PSK_TOKEN_KEY, token, { secure: true, sameSite: 'strict' });
} else {
Cookies.remove(PSK_TOKEN_KEY);
}
}
18 changes: 6 additions & 12 deletions packages/auth-plugins/src/AuthPluginPsk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { useBroadcastLoginListener } from '@deephaven/jsapi-components';
import Log from '@deephaven/log';
import { getErrorMessage } from '@deephaven/utils';
import Cookies from 'js-cookie';
import { AuthPlugin, AuthPluginProps } from './AuthPlugin';
import {
AuthPlugin,
AuthPluginProps,
PSK_TOKEN_KEY,
storeCookieToken,
} from './AuthPlugin';
import LoginForm from './LoginForm';
import Login from './Login';
import AuthenticationError from './AuthenticationError';
Expand All @@ -15,8 +20,6 @@ const AUTH_TYPE = 'io.deephaven.authentication.psk.PskAuthenticationHandler';

const PSK_QUERY_PARAM_KEY = 'psk';

const PSK_TOKEN_KEY = 'io.deephaven.web.client.auth.psk.token';

const log = Log.module('AuthPluginPsk');

function getWindowToken(): string | null {
Expand All @@ -35,15 +38,6 @@ function readCookieToken(): string | null {
return Cookies.get(PSK_TOKEN_KEY) ?? null;
}

function storeCookieToken(token: string | null): void {
log.debug2('Storing token in cookie', token);
if (token != null) {
Cookies.set(PSK_TOKEN_KEY, token, { secure: true, sameSite: 'strict' });
} else {
Cookies.remove(PSK_TOKEN_KEY);
}
}

export type AuthPluginPskProps = AuthPluginProps & {
/** Custom path to a logo to display on the login screen */
logoPath?: string;
Expand Down
Loading