aboutsummaryrefslogtreecommitdiff
path: root/modern/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-02-11 14:14:46 -0800
committerAnton Tananaev <anton@traccar.org>2023-02-11 14:14:46 -0800
commit14857963be924ea669ab9d09df06e8fcd87c6c68 (patch)
tree79b1483c677ba573f1457ecfa705414f92d0f8f6 /modern/src
parent0d530ab6340605354d00e67ec7d8d1272bafd9f3 (diff)
downloadtrackermap-web-14857963be924ea669ab9d09df06e8fcd87c6c68.tar.gz
trackermap-web-14857963be924ea669ab9d09df06e8fcd87c6c68.tar.bz2
trackermap-web-14857963be924ea669ab9d09df06e8fcd87c6c68.zip
Redirect to login
Diffstat (limited to 'modern/src')
-rw-r--r--modern/src/SocketController.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index 521ad54d..7dd073fd 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -1,12 +1,11 @@
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector, connect } from 'react-redux';
+import { useNavigate } from 'react-router-dom';
import { Snackbar } from '@mui/material';
-
import { devicesActions, sessionActions } from './store';
import { useEffectAsync } from './reactHelper';
import { useTranslation } from './common/components/LocalizationProvider';
import { snackBarDurationLongMs } from './common/util/duration';
-
import alarm from './resources/alarm.mp3';
import { eventsActions } from './store/events';
import useFeatures from './common/util/useFeatures';
@@ -16,6 +15,7 @@ const logoutCode = 4000;
const SocketController = () => {
const dispatch = useDispatch();
+ const navigate = useNavigate();
const t = useTranslation();
const authenticated = useSelector((state) => !!state.session.user);
@@ -48,12 +48,13 @@ const SocketController = () => {
if (devicesResponse.ok) {
dispatch(devicesActions.update(await devicesResponse.json()));
}
- const positionsResponse = await fetch('/api/positions', {
- headers: { 'Content-Type': 'application/json' },
- });
+ const positionsResponse = await fetch('/api/positions');
if (positionsResponse.ok) {
dispatch(sessionActions.updatePositions(await positionsResponse.json()));
}
+ if (devicesResponse.status === 401 || positionsResponse.status === 401) {
+ navigate('/login');
+ }
} catch (error) {
// ignore errors
}