import React, { useEffect } from "react"; import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; import Navbar from "./components/layout/Navbar"; import Landing from "./components/layout/Landing"; import Register from "./components/auth/Register"; import Login from "./components/auth/Login"; import Alert from "./components/layout/Alert"; import Dashboard from "./components/dashboard/Dashboard"; import ProfileForm from "./components/profile-forms/ProfileForm"; import AddExperience from "./components/profile-forms/AddExperience"; import AddEducation from "./components/profile-forms/AddEducation"; import Profiles from "./components/profiles/Profiles"; import Profile from "./components/profile/Profile"; import Posts from "./components/posts/Posts"; import Post from "./components/post/Post"; import NotFound from "./components/layout/NotFound"; import PrivateRoute from "./components/routing/PrivateRoute"; // Redux import { Provider } from "react-redux"; import store from "./store"; import { loadUser } from "./actions/auth"; import setAuthToken from "./utils/setAuthToken"; import { logOut } from "./reducers/auth"; const App = () => { useEffect(() => { if (localStorage.token) { setAuthToken(localStorage.token); } store.dispatch(loadUser()); window.addEventListener("storage", () => { if (!localStorage.token) store.dispatch(logOut); }); }, []); return ( } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> ); }; export default App;