text: import React, { Component } from "react";
  import "./App.css";
  import NavBar from "./components/layout/Navbar";
  import Footer from "./components/layout/Footer";
  import Landing from "./components/layout/Landing";
  import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
  import Register from "./components/auth/Register";
  import { Provider } from "react-redux"; //Provider provides application with store of the state
  import store from "./store";
  import Login from "./components/auth/Login";
  import setAuthToken from "./utils/setAuthToken";
  import { setCurrentUser, logoutUser } from "./actions/authActions";
  import jwt_decode from "jwt-decode";
  import Dashboard from "./components/dashboard/Dashboard";
  import PrivateRoute from "./components/common/PrivateRoute";
  import Posts from "./components/posts/Posts";
  import Post from "./components/post/Post";
  import CreateProfile from "./components/create-profile/CreateProfile";
  import EditProfile from "./components/edit-profile/EditProfile";
  import AddBookToRead from "./components/edit-profile/AddBookToRead";
  import AddBookRead from "./components/edit-profile/AddBookRead";
  import Profile from "./components/profile/Profile";
  import Profiles from "./components/profiles/Profiles";
  import NotFound from "./components/not-found/NotFound";
  
  //Check for token
  if (localStorage.jwtToken) {
    //Set auth token header auth
    setAuthToken(localStorage.jwtToken);
    //Decode token and get user info and exp
    const decoded = jwt_decode(localStorage.jwtToken);
    //Set user and isAuthenticated
    store.dispatch(setCurrentUser(decoded));
  
    //Check for expired token
    const currentTime = Date.now() / 1000;
    if (decoded.exp < currentTime) {
      //Logout user
      store.dispatch(logoutUser());
      //TODO: Clear current profile
      //Redirect to login
      window.location.href = "/login";
    }
  }
  
  class App extends Component {
    render() {
      return (
        <Provider store={store}>
          <Router>
            <div className="App">
              <NavBar />
              <Route exact path="/" component={Landing} />
              <div className="container">
                <Route exact path="/register" component={Register} />
                <Route exact path="/login" component={Login} />
                <Switch>
                  <PrivateRoute exact path="/dashboard" component={Dashboard} />
                </Switch>
                <Switch>
                  <PrivateRoute
                    exact
                    path="/create-profile"
                    component={CreateProfile}
                  />
                </Switch>
                <Switch>
                  <PrivateRoute exact path="/edit-bio" component={EditProfile} />
                </Switch>
                <Switch>
                  <PrivateRoute
                    exact
                    path="/add-bookstoread"
                    component={AddBookToRead}
                  />
                </Switch>
                <Switch>
                  <PrivateRoute
                    exact
                    path="/add-booksread"
                    component={AddBookRead}
                  />
                </Switch>
                <Switch>
                  <PrivateRoute exact path="/feed" component={Posts} />
                </Switch>
                <Switch>
                  <PrivateRoute exact path="/post/:id" component={Post} />
                </Switch>
                <Route exact path="/profile/:handle" component={Profile} />
                <Route exact path="/profiles" component={Profiles} />
                <Route exact path="/not-found" component={NotFound} />
              </div>
              <Footer />
            </div>
          </Router>
        </Provider>
      );
    }
  }
  
  export default App;
  