mirror of
https://github.com/ansible/awx.git
synced 2026-03-24 12:25:01 -02:30
kick back to login page if config gets 401 response
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState, useCallback } from 'react';
|
||||||
import { useHistory, useLocation, withRouter } from 'react-router-dom';
|
import { useHistory, useLocation, withRouter } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Nav,
|
Nav,
|
||||||
@@ -40,15 +40,16 @@ function AppContainer({ i18n, navRouteConfig = [], children }) {
|
|||||||
const [config, setConfig] = useState({});
|
const [config, setConfig] = useState({});
|
||||||
const [configError, setConfigError] = useState(null);
|
const [configError, setConfigError] = useState(null);
|
||||||
const [isAboutModalOpen, setIsAboutModalOpen] = useState(false);
|
const [isAboutModalOpen, setIsAboutModalOpen] = useState(false);
|
||||||
|
const [isReady, setIsReady] = useState(false);
|
||||||
|
|
||||||
const handleAboutModalOpen = () => setIsAboutModalOpen(true);
|
const handleAboutModalOpen = () => setIsAboutModalOpen(true);
|
||||||
const handleAboutModalClose = () => setIsAboutModalOpen(false);
|
const handleAboutModalClose = () => setIsAboutModalOpen(false);
|
||||||
const handleConfigErrorClose = () => setConfigError(null);
|
const handleConfigErrorClose = () => setConfigError(null);
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = useCallback(async () => {
|
||||||
await RootAPI.logout();
|
await RootAPI.logout();
|
||||||
history.replace('/login');
|
history.replace('/login');
|
||||||
};
|
}, [history]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadConfig = async () => {
|
const loadConfig = async () => {
|
||||||
@@ -63,12 +64,21 @@ function AppContainer({ i18n, navRouteConfig = [], children }) {
|
|||||||
},
|
},
|
||||||
] = await Promise.all([ConfigAPI.read(), MeAPI.read()]);
|
] = await Promise.all([ConfigAPI.read(), MeAPI.read()]);
|
||||||
setConfig({ ...data, me });
|
setConfig({ ...data, me });
|
||||||
|
setIsReady(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.response.status === 401) {
|
||||||
|
handleLogout();
|
||||||
|
return;
|
||||||
|
}
|
||||||
setConfigError(err);
|
setConfigError(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
loadConfig();
|
loadConfig();
|
||||||
}, [config, pathname]);
|
}, [config, pathname, handleLogout]);
|
||||||
|
|
||||||
|
if (!isReady) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const header = (
|
const header = (
|
||||||
<PageHeader
|
<PageHeader
|
||||||
|
|||||||
Reference in New Issue
Block a user