Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontend/backend] correct logout redirection #1790

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions openbas-front/src/admin/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box } from '@mui/material';
import { makeStyles, useTheme } from '@mui/styles';
import { lazy, Suspense } from 'react';
import { Route, Routes, useNavigate } from 'react-router-dom';
import { lazy, Suspense, useEffect } from 'react';
import { Navigate, Route, Routes, useNavigate } from 'react-router-dom';

import type { LoggedHelper } from '../actions/helper';
import { fetchTags } from '../actions/Tag';
Expand Down Expand Up @@ -47,9 +47,13 @@ const Index = () => {
const { logged, settings } = useHelper((helper: LoggedHelper) => {
return { logged: helper.logged(), settings: helper.getPlatformSettings() };
});
if (logged.isOnlyPlayer) {
navigate('/private');
}

useEffect(() => {
if (logged.isOnlyPlayer) {
navigate('/');
}
}, [logged]);

const boxSx = {
flexGrow: 1,
padding: 3,
Expand Down Expand Up @@ -99,7 +103,11 @@ const Index = () => {
<Route path="mitigations" element={errorWrapper(Mitigations)()} />
<Route path="integrations/*" element={errorWrapper(IndexIntegrations)()} />
<Route path="agents/*" element={errorWrapper(IndexAgents)()} />
<Route path="settings/*" element={errorWrapper(IndexSettings)()} />
<Route
path="settings/*"
element={logged.admin ? errorWrapper(IndexSettings)()
: <Navigate to="/" replace={true} />}
/>
{/* Not found */}
<Route path="*" element={<NotFound />} />
</Routes>
Expand Down
1 change: 1 addition & 0 deletions openbas-front/src/admin/components/nav/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const TopBar: React.FC = () => {
});
const handleLogout = async () => {
await dispatch(logout());
navigate('/');
handleCloseMenu();
};

Expand Down
4 changes: 3 additions & 1 deletion openbas-front/src/private/components/nav/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppBar, IconButton, Menu, MenuItem, MenuProps, Toolbar } from '@mui/mat
import { makeStyles, useTheme } from '@mui/styles';
import { useState } from 'react';
import * as React from 'react';
import { Link } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';

import { logout } from '../../../actions/Application';
import { useFormatter } from '../../../components/i18n';
Expand Down Expand Up @@ -38,6 +38,7 @@ const TopBar: React.FC = () => {
const theme = useTheme<Theme>();
const classes = useStyles();
const { t } = useFormatter();
const navigate = useNavigate();
const [open, setOpen] = useState(false);
const [anchorEl, setAnchorEl] = useState<MenuProps['anchorEl']>(null);
const dispatch = useAppDispatch();
Expand All @@ -51,6 +52,7 @@ const TopBar: React.FC = () => {
};
const handleLogout = async () => {
await dispatch(logout());
navigate('/');
setOpen(false);
};
return (
Expand Down