From e56c746b608fe15e79ac75bbdd1c25e78594aecf Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Wed, 2 Sep 2020 17:51:38 +0300 Subject: [PATCH] - client: Do not redirect to login page from install and login pages Close #2036 Squashed commit of the following: commit 9880b80671973929b732bb45f767392627ddecc1 Merge: 55a51ea2 7b9cef3a Author: ArtemBaskal Date: Wed Sep 2 16:34:43 2020 +0300 Merge branch 'master' into fix/unauthorized_redirect_logic commit 55a51ea2947a43c339c8e5111ba79e4d52b26c84 Merge: 170b7387 7931e506 Author: ArtemBaskal Date: Wed Sep 2 15:54:38 2020 +0300 Merge branch 'master' into fix/unauthorized_redirect_logic commit 170b7387b06e6c9b30b50cc673f7457976007b0f Author: ArtemBaskal Date: Tue Aug 25 17:13:02 2020 +0300 - client: Do not redirect to login page from install and login pages --- client/src/actions/login.js | 4 +++- client/src/api/Api.js | 18 ++++++++++++------ client/src/helpers/constants.js | 6 ++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/client/src/actions/login.js b/client/src/actions/login.js index afc0c25b..227fab03 100644 --- a/client/src/actions/login.js +++ b/client/src/actions/login.js @@ -2,6 +2,7 @@ import { createAction } from 'redux-actions'; import apiClient from '../api/Api'; import { addErrorToast } from './toasts'; +import { HTML_PAGES } from '../helpers/constants'; export const processLoginRequest = createAction('PROCESS_LOGIN_REQUEST'); export const processLoginFailure = createAction('PROCESS_LOGIN_FAILURE'); @@ -11,7 +12,8 @@ export const processLogin = (values) => async (dispatch) => { dispatch(processLoginRequest()); try { await apiClient.login(values); - const dashboardUrl = window.location.origin + window.location.pathname.replace('/login.html', '/'); + const dashboardUrl = window.location.origin + + window.location.pathname.replace(HTML_PAGES.LOGIN, HTML_PAGES.MAIN); window.location.replace(dashboardUrl); dispatch(processLoginSuccess()); } catch (error) { diff --git a/client/src/api/Api.js b/client/src/api/Api.js index 86791162..fc42eeb4 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -1,26 +1,32 @@ import axios from 'axios'; import { getPathWithQueryString } from '../helpers/helpers'; -import { QUERY_LOGS_PAGE_LIMIT, R_PATH_LAST_PART } from '../helpers/constants'; +import { QUERY_LOGS_PAGE_LIMIT, HTML_PAGES, R_PATH_LAST_PART } from '../helpers/constants'; import { BASE_URL } from '../../constants'; class Api { baseUrl = BASE_URL; async makeRequest(path, method = 'POST', config) { + const url = `${this.baseUrl}/${path}`; + try { const response = await axios({ - url: `${this.baseUrl}/${path}`, + url, method, ...config, }); return response.data; } catch (error) { - console.error(error); - const errorPath = `${this.baseUrl}/${path}`; + const errorPath = url; if (error.response) { - if (error.response.status === 403) { - const loginPageUrl = window.location.href.replace(R_PATH_LAST_PART, '/login.html'); + const { pathname } = document.location; + const shouldRedirect = pathname !== HTML_PAGES.LOGIN + && pathname !== HTML_PAGES.INSTALL; + + if (error.response.status === 403 && shouldRedirect) { + const loginPageUrl = window.location.href + .replace(R_PATH_LAST_PART, HTML_PAGES.LOGIN); window.location.replace(loginPageUrl); return false; } diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index 2c8de73e..e0075a25 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -21,6 +21,12 @@ export const R_UNIX_ABSOLUTE_PATH = /^(\/[^/\x00]+)+$/; // eslint-disable-next-line no-control-regex export const R_WIN_ABSOLUTE_PATH = /^([a-zA-Z]:)?(\\|\/)(?:[^\\/:*?"<>|\x00]+\\)*[^\\/:*?"<>|\x00]*$/; +export const HTML_PAGES = { + INSTALL: '/install.html', + LOGIN: '/login.html', + MAIN: '/', +}; + export const STATS_NAMES = { avg_processing_time: 'average_processing_time', blocked_filtering: 'Blocked by filters',