- 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 <a.baskal@adguard.com>
Date:   Wed Sep 2 16:34:43 2020 +0300

    Merge branch 'master' into fix/unauthorized_redirect_logic

commit 55a51ea2947a43c339c8e5111ba79e4d52b26c84
Merge: 170b7387 7931e506
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Wed Sep 2 15:54:38 2020 +0300

    Merge branch 'master' into fix/unauthorized_redirect_logic

commit 170b7387b06e6c9b30b50cc673f7457976007b0f
Author: ArtemBaskal <a.baskal@adguard.com>
Date:   Tue Aug 25 17:13:02 2020 +0300

    - client: Do not redirect to login page from install and login pages
This commit is contained in:
Artem Baskal 2020-09-02 17:51:38 +03:00
parent 7b9cef3a08
commit e56c746b60
3 changed files with 21 additions and 7 deletions

View file

@ -2,6 +2,7 @@ import { createAction } from 'redux-actions';
import apiClient from '../api/Api'; import apiClient from '../api/Api';
import { addErrorToast } from './toasts'; import { addErrorToast } from './toasts';
import { HTML_PAGES } from '../helpers/constants';
export const processLoginRequest = createAction('PROCESS_LOGIN_REQUEST'); export const processLoginRequest = createAction('PROCESS_LOGIN_REQUEST');
export const processLoginFailure = createAction('PROCESS_LOGIN_FAILURE'); export const processLoginFailure = createAction('PROCESS_LOGIN_FAILURE');
@ -11,7 +12,8 @@ export const processLogin = (values) => async (dispatch) => {
dispatch(processLoginRequest()); dispatch(processLoginRequest());
try { try {
await apiClient.login(values); 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); window.location.replace(dashboardUrl);
dispatch(processLoginSuccess()); dispatch(processLoginSuccess());
} catch (error) { } catch (error) {

View file

@ -1,26 +1,32 @@
import axios from 'axios'; import axios from 'axios';
import { getPathWithQueryString } from '../helpers/helpers'; 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'; import { BASE_URL } from '../../constants';
class Api { class Api {
baseUrl = BASE_URL; baseUrl = BASE_URL;
async makeRequest(path, method = 'POST', config) { async makeRequest(path, method = 'POST', config) {
const url = `${this.baseUrl}/${path}`;
try { try {
const response = await axios({ const response = await axios({
url: `${this.baseUrl}/${path}`, url,
method, method,
...config, ...config,
}); });
return response.data; return response.data;
} catch (error) { } catch (error) {
console.error(error); const errorPath = url;
const errorPath = `${this.baseUrl}/${path}`;
if (error.response) { if (error.response) {
if (error.response.status === 403) { const { pathname } = document.location;
const loginPageUrl = window.location.href.replace(R_PATH_LAST_PART, '/login.html'); 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); window.location.replace(loginPageUrl);
return false; return false;
} }

View file

@ -21,6 +21,12 @@ export const R_UNIX_ABSOLUTE_PATH = /^(\/[^/\x00]+)+$/;
// eslint-disable-next-line no-control-regex // eslint-disable-next-line no-control-regex
export const R_WIN_ABSOLUTE_PATH = /^([a-zA-Z]:)?(\\|\/)(?:[^\\/:*?"<>|\x00]+\\)*[^\\/:*?"<>|\x00]*$/; 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 = { export const STATS_NAMES = {
avg_processing_time: 'average_processing_time', avg_processing_time: 'average_processing_time',
blocked_filtering: 'Blocked by filters', blocked_filtering: 'Blocked by filters',