Skip to content

Commit

Permalink
Show a prompt when authentication fails to refresh the browser
Browse files Browse the repository at this point in the history
- Informs the user an error has occurred and they can press Refresh to try again
  • Loading branch information
mofojed committed Mar 29, 2023
1 parent 4bbff41 commit b72e295
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
7 changes: 0 additions & 7 deletions packages/code-studio/src/main/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@ function AppInit(props: AppInitProps) {
setError(`Server shutdown: ${detail ?? 'Unknown reason'}`);
setDisconnectError(null);
});
connection.addEventListener(
dh.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
event => {
log.warn('Reconnect authentication failed');
setError('Reconnect authentication failed');
}
);

const sessionWrapper = await loadSessionWrapper(connection);
const name = 'user';
Expand Down
31 changes: 30 additions & 1 deletion packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Button,
InfoModal,
LoadingSpinner,
BasicModal,
} from '@deephaven/components';
import {
IrisGridModel,
Expand Down Expand Up @@ -156,6 +157,7 @@ interface AppMainContainerProps {

interface AppMainContainerState {
contextActions: ContextAction[];
isAuthFailed: boolean;
isDisconnected: boolean;
isPanelsMenuShown: boolean;
isSettingsMenuShown: boolean;
Expand Down Expand Up @@ -185,6 +187,11 @@ export class AppMainContainer extends Component<
);
}

static handleRefresh() {
log.info('Refreshing application');
window.location.reload();
}

constructor(props: AppMainContainerProps & RouteComponentProps) {
super(props);
this.handleSettingsMenuHide = this.handleSettingsMenuHide.bind(this);
Expand Down Expand Up @@ -213,6 +220,7 @@ export class AppMainContainer extends Component<
this.openNotebookFromURL = this.openNotebookFromURL.bind(this);
this.handleDisconnect = this.handleDisconnect.bind(this);
this.handleReconnect = this.handleReconnect.bind(this);
this.handleReconnectAuthFailed = this.handleReconnectAuthFailed.bind(this);

this.importElement = React.createRef();

Expand Down Expand Up @@ -242,6 +250,7 @@ export class AppMainContainer extends Component<
isGlobal: true,
},
],
isAuthFailed: false,
isDisconnected: false,
isPanelsMenuShown: false,
isSettingsMenuShown: false,
Expand Down Expand Up @@ -555,6 +564,10 @@ export class AppMainContainer extends Component<
this.setState({ isDisconnected: false });
}

handleReconnectAuthFailed() {
this.setState({ isAuthFailed: true });
}

/**
* Import the provided file and set it in the workspace data (which should then load it in the dashboard)
* @param file JSON file to import
Expand Down Expand Up @@ -661,6 +674,10 @@ export class AppMainContainer extends Component<
dh.IdeConnection.EVENT_RECONNECT,
this.handleReconnect
);
connection.addEventListener(
dh.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
this.handleReconnectAuthFailed
);
}

stopListeningForDisconnect() {
Expand All @@ -673,6 +690,10 @@ export class AppMainContainer extends Component<
dh.IdeConnection.EVENT_RECONNECT,
this.handleReconnect
);
connection.removeEventListener(
dh.CoreClient.EVENT_RECONNECT_AUTH_FAILED,
this.handleReconnectAuthFailed
);
}

hydrateDefault(
Expand Down Expand Up @@ -788,6 +809,7 @@ export class AppMainContainer extends Component<
const { canUsePanels } = permissions;
const {
contextActions,
isAuthFailed,
isDisconnected,
isPanelsMenuShown,
isSettingsMenuShown,
Expand Down Expand Up @@ -929,7 +951,7 @@ export class AppMainContainer extends Component<
onChange={this.handleImportLayoutFiles}
/>
<InfoModal
isOpen={isDisconnected}
isOpen={isDisconnected && !isAuthFailed}
icon={vsDebugDisconnect}
title={
<>
Expand All @@ -938,6 +960,13 @@ export class AppMainContainer extends Component<
}
subtitle="Please check your network connection."
/>
<BasicModal
confirmButtonText="Refresh"
onConfirm={AppMainContainer.handleRefresh}
isOpen={isAuthFailed}
headerText="Authentication failed"
bodyText="Credentials are invalid. Please refresh your browser to try and reconnect."
/>
</div>
);
}
Expand Down

0 comments on commit b72e295

Please sign in to comment.