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',