mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 13:39:27 -02:30
fix login/logout redirect behavior
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import React, { Component, Fragment } from 'react';
|
import React, { Component, Fragment } from 'react';
|
||||||
|
import { withRouter } from 'react-router-dom';
|
||||||
import { global_breakpoint_md } from '@patternfly/react-tokens';
|
import { global_breakpoint_md } from '@patternfly/react-tokens';
|
||||||
import {
|
import {
|
||||||
Nav,
|
Nav,
|
||||||
@@ -66,8 +67,9 @@ class App extends Component {
|
|||||||
|
|
||||||
// eslint-disable-next-line class-methods-use-this
|
// eslint-disable-next-line class-methods-use-this
|
||||||
async handleLogout() {
|
async handleLogout() {
|
||||||
|
const { history } = this.props;
|
||||||
await RootAPI.logout();
|
await RootAPI.logout();
|
||||||
window.location.replace('/#/login');
|
history.replace('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAboutOpen() {
|
handleAboutOpen() {
|
||||||
@@ -193,4 +195,4 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export { App as _App };
|
export { App as _App };
|
||||||
export default withI18n()(App);
|
export default withI18n()(withRouter(App));
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ export function main(render) {
|
|||||||
const el = document.getElementById('app');
|
const el = document.getElementById('app');
|
||||||
document.title = `Ansible ${BrandName}`;
|
document.title = `Ansible ${BrandName}`;
|
||||||
|
|
||||||
const defaultRedirect = () => <Redirect to="/home" />;
|
|
||||||
const removeTrailingSlash = (
|
const removeTrailingSlash = (
|
||||||
<Route
|
<Route
|
||||||
exact
|
exact
|
||||||
@@ -56,31 +55,38 @@ export function main(render) {
|
|||||||
}) => <Redirect to={`${pathname.slice(0, -1)}${search}${hash}`} />}
|
}) => <Redirect to={`${pathname.slice(0, -1)}${search}${hash}`} />}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const loginRoutes = (
|
|
||||||
<Switch>
|
const defaultRedirect = () => {
|
||||||
{removeTrailingSlash}
|
if (isAuthenticated(document.cookie)) {
|
||||||
<Route
|
return <Redirect to="/home" />;
|
||||||
path="/login"
|
}
|
||||||
render={() => <Login isAuthenticated={isAuthenticated} />}
|
return (
|
||||||
/>
|
<Switch>
|
||||||
<Redirect to="/login" />
|
{removeTrailingSlash}
|
||||||
</Switch>
|
<Route
|
||||||
);
|
path="/login"
|
||||||
|
render={() => <Login isAuthenticated={isAuthenticated} />}
|
||||||
|
/>
|
||||||
|
<Redirect to="/login" />
|
||||||
|
</Switch>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
<RootProvider>
|
<RootProvider>
|
||||||
<I18n>
|
<I18n>
|
||||||
{({ i18n }) => (
|
{({ i18n }) => (
|
||||||
<Background>
|
<Background>
|
||||||
{!isAuthenticated(document.cookie) ? (
|
<Switch>
|
||||||
loginRoutes
|
{removeTrailingSlash}
|
||||||
) : (
|
<Route path="/login" render={defaultRedirect} />
|
||||||
<Switch>
|
<Route exact path="/" render={defaultRedirect} />
|
||||||
{removeTrailingSlash}
|
<Route
|
||||||
<Route path="/login" render={defaultRedirect} />
|
render={() => {
|
||||||
<Route exact path="/" render={defaultRedirect} />
|
if (!isAuthenticated(document.cookie)) {
|
||||||
<Route
|
return <Redirect to="/login" />;
|
||||||
render={() => (
|
}
|
||||||
|
return (
|
||||||
<App
|
<App
|
||||||
navLabel={i18n._(t`Primary Navigation`)}
|
navLabel={i18n._(t`Primary Navigation`)}
|
||||||
routeGroups={[
|
routeGroups={[
|
||||||
@@ -250,10 +256,10 @@ export function main(render) {
|
|||||||
return <Switch>{routeList}</Switch>;
|
return <Switch>{routeList}</Switch>;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
);
|
||||||
/>
|
}}
|
||||||
</Switch>
|
/>
|
||||||
)}
|
</Switch>
|
||||||
</Background>
|
</Background>
|
||||||
)}
|
)}
|
||||||
</I18n>
|
</I18n>
|
||||||
|
|||||||
Reference in New Issue
Block a user