mirror of
https://github.com/Funkoala14/KnowledgeBase_OOIN.git
synced 2025-06-08 07:20:55 +08:00
30 lines
792 B
JavaScript
30 lines
792 B
JavaScript
import { useDispatch, useSelector } from 'react-redux';
|
|
import AppRouter from './router/router';
|
|
import { checkAuthThunk } from './store/auth/auth.thunk';
|
|
import { useEffect } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { login } from './store/auth/auth.slice';
|
|
|
|
function App() {
|
|
const navigate = useNavigate();
|
|
const dispatch = useDispatch();
|
|
|
|
const { user } = useSelector((state) => state.auth);
|
|
|
|
useEffect(() => {
|
|
handleCheckAuth();
|
|
}, [dispatch]);
|
|
|
|
const handleCheckAuth = async () => {
|
|
console.log('app handleCheckAuth');
|
|
try {
|
|
await dispatch(checkAuthThunk()).unwrap();
|
|
if (user) navigate('/');
|
|
} catch (error) {}
|
|
};
|
|
|
|
return <AppRouter></AppRouter>;
|
|
}
|
|
|
|
export default App;
|