fix signin

This commit is contained in:
Proddy
2023-06-18 17:12:43 +02:00
parent ce1b9f22cb
commit bc6b48bd07
4 changed files with 45 additions and 49 deletions

View File

@@ -1,13 +1,13 @@
import { useCallback, useEffect } from 'react'; // import { useCallback, useEffect } from 'react';
import { Navigate, Routes, Route, useNavigate, useLocation } from 'react-router-dom'; import { Navigate, Routes, Route } from 'react-router-dom';
import Dashboard from './project/Dashboard'; import Dashboard from './project/Dashboard';
import Help from './project/Help'; import Help from './project/Help';
import Settings from './project/Settings'; import Settings from './project/Settings';
import type { AxiosError } from 'axios'; // import type { AxiosError } from 'axios';
import type { FC } from 'react'; import type { FC } from 'react';
import * as AuthenticationApi from 'api/authentication'; // import * as AuthenticationApi from 'api/authentication';
import { AXIOS } from 'api/endpoints'; // import { AXIOS } from 'api/endpoints';
import { Layout, RequireAdmin } from 'components'; import { Layout, RequireAdmin } from 'components';
import AccessPoint from 'framework/ap/AccessPoint'; import AccessPoint from 'framework/ap/AccessPoint';
@@ -17,11 +17,11 @@ import NetworkTime from 'framework/ntp/NetworkTime';
import Security from 'framework/security/Security'; import Security from 'framework/security/Security';
import System from 'framework/system/System'; import System from 'framework/system/System';
const AuthenticatedRouting: FC = () => { const AuthenticatedRouting: FC = () => (
const location = useLocation(); // const location = useLocation();
const navigate = useNavigate(); // const navigate = useNavigate();
// TODO fix this - how to redirect on a 401 // TODO not sure if this is needed, to redirect on 401. If so add incerceptor to Alova
// const handleApiResponseError = useCallback( // const handleApiResponseError = useCallback(
// (error: AxiosError) => { // (error: AxiosError) => {
// if (error.response && error.response.status === 401) { // if (error.response && error.response.status === 401) {
@@ -34,12 +34,10 @@ const AuthenticatedRouting: FC = () => {
// ); // );
// useEffect(() => { // useEffect(() => {
// // TODO replace AXIOS.interceptors.response.use ???
// const axiosHandlerId = AXIOS.interceptors.response.use((response) => response, handleApiResponseError); // const axiosHandlerId = AXIOS.interceptors.response.use((response) => response, handleApiResponseError);
// return () => AXIOS.interceptors.response.eject(axiosHandlerId); // return () => AXIOS.interceptors.response.eject(axiosHandlerId);
// }, [handleApiResponseError]); // }, [handleApiResponseError]);
return (
<Layout> <Layout>
<Routes> <Routes>
<Route path="/dashboard/*" element={<Dashboard />} /> <Route path="/dashboard/*" element={<Dashboard />} />
@@ -69,7 +67,5 @@ const AuthenticatedRouting: FC = () => {
<Route path="/*" element={<Navigate to="/" />} /> <Route path="/*" element={<Navigate to="/" />} />
</Routes> </Routes>
</Layout> </Layout>
); );
};
export default AuthenticatedRouting; export default AuthenticatedRouting;

View File

@@ -49,13 +49,11 @@ export const alovaInstance = createAlova({
return data; return data;
}, },
// TODO handle errors // TODO how best to handle alova http errors like 401
// Interceptor for request failure // Interceptor for request failure
// This interceptor will be entered when the request is wrong. // This interceptor will be entered when the request is wrong.
// The second parameter is the method instance of the current request, you can use it to synchronize the configuration information before and after the request // The second parameter is the method instance of the current request, you can use it to synchronize the configuration information before and after the request
onError: (error, method) => { onError: (error) => {
console.log('error:', error); // TODO fix me
console.log('method:', method); // TODO fix me
alert(error.message); alert(error.message);
} }
} }

View File

@@ -56,6 +56,9 @@ const Authentication: FC<RequiredChildrenProps> = ({ children }) => {
setMe(undefined); setMe(undefined);
setInitialized(true); setInitialized(true);
}); });
} else {
setMe(undefined);
setInitialized(true);
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);

View File

@@ -29,13 +29,11 @@ import {
} from '@mui/material'; } from '@mui/material';
import { useRequest } from 'alova'; import { useRequest } from 'alova';
import axios from 'axios'; import { useContext, useState } from 'react';
import { useContext, useState, useEffect } from 'react';
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
import RestartMonitor from './RestartMonitor'; import RestartMonitor from './RestartMonitor';
import type { FC } from 'react'; import type { FC } from 'react';
import type { Version } from 'types';
import * as SystemApi from 'api/system'; import * as SystemApi from 'api/system';
import { ButtonRow, FormLoader, SectionContent, MessageBox } from 'components'; import { ButtonRow, FormLoader, SectionContent, MessageBox } from 'components';
import { AuthenticatedContext } from 'contexts/authentication'; import { AuthenticatedContext } from 'contexts/authentication';
@@ -71,6 +69,7 @@ const SystemStatusForm: FC = () => {
immediate: false immediate: false
}); });
// fetch versions from GH on load
const { data: latestVersion } = useRequest(SystemApi.getStableVersion); const { data: latestVersion } = useRequest(SystemApi.getStableVersion);
const { data: latestDevVersion } = useRequest(SystemApi.getDevVersion); const { data: latestDevVersion } = useRequest(SystemApi.getDevVersion);