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