From: Lucas Di Pentima Date: Thu, 27 Aug 2020 21:51:53 +0000 (-0300) Subject: 16680: Logs out the user when token expires. X-Git-Tag: 2.1.0~11^2~2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/202a49e579c8ba643f6bc7f2bcb55fcf57d12eb8 16680: Logs out the user when token expires. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/index.tsx b/src/index.tsx index d07d3c9e..0a51ed3c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -14,7 +14,7 @@ import { configureStore, RootStore } from '~/store/store'; import { ConnectedRouter } from "react-router-redux"; import { ApiToken } from "~/views-components/api-token/api-token"; import { AddSession } from "~/views-components/add-session/add-session"; -import { initAuth } from "~/store/auth/auth-action"; +import { initAuth, logout } from "~/store/auth/auth-action"; import { createServices } from "~/services/services"; import { MuiThemeProvider } from '@material-ui/core/styles'; import { CustomTheme } from '~/common/custom-theme'; @@ -108,8 +108,10 @@ fetchConfig() if (showSnackBar) { console.error("Backend error:", error); - if (error.errors[0].indexOf("not found") > -1) { + if (error.status === 404) { store.dispatch(openNotFoundDialog()); + } else if (error.status === 401 && error.errors[0].indexOf("Not logged in") > -1) { + store.dispatch(logout()); } else { store.dispatch(snackbarActions.OPEN_SNACKBAR({ message: `${error.errors diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index e00a3d7d..d605611f 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -9,6 +9,7 @@ import { ApiActions } from "~/services/api/api-actions"; import * as QueryString from "query-string"; interface Errors { + status: number; errors: string[]; errorToken: string; } @@ -80,6 +81,7 @@ export class CommonService { .catch(({ response }) => { actions.progressFn(reqId, false); const errors = CommonService.mapResponseKeys(response) as Errors; + errors.status = response.status; actions.errorFn(reqId, errors, showErrors); throw errors; });