feat: add login page and auth logic

This commit is contained in:
2025-06-10 17:50:28 +05:00
parent 599bf22bda
commit d55a99aafd
6 changed files with 120 additions and 8 deletions

View File

@@ -9,6 +9,8 @@ import RunningProcessesPage from './RunningProcessesPage';
import AccountsPage from './AccountsPage';
import EventsListPage from './EventsListPage';
import ConfigurationPage from './ConfigurationPage';
import { useSetUserSelector } from '../store/user';
import { UserService } from '../services/user';
export default function MainLayout() {
const navigate = useNavigate();
@@ -19,6 +21,8 @@ export default function MainLayout() {
const [width, setWidth] = useState<number | string>('15%');
const [collapsedWidth, setCollapsedWidth] = useState(50);
const setUser = useSetUserSelector();
const calculateWidths = () => {
const windowWidth = window.innerWidth;
const expanded = Math.min(Math.max(windowWidth * 0.15, 180), 240);
@@ -54,6 +58,21 @@ export default function MainLayout() {
navigate(key);
}
useEffect(() => {
const token = localStorage.getItem('accessToken');
if (!token) {
navigate('/login');
} else {
if (localStorage.getItem('user')) {
setUser(JSON.parse(localStorage.getItem('user') as string));
} else {
UserService.getProfile().then((user) => {
setUser(user);
});
}
}
}, []);
return (
<Layout style={{ minHeight: '100vh' }}>
<Sider