- client: Do not redirect to login page from install and login pages
Close #2036 Squashed commit of the following: commit 9880b80671973929b732bb45f767392627ddecc1 Merge: 55a51ea27b9cef3aAuthor: 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: 170b73877931e506Author: 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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user