I have a react app where on loading the App component first the app checks whether there is token in localstorage, If it is there then it takes the token and verifies it, If the token is valid then the user is taken to dashboard and if it isn't the user is taken to login page, But however what is happening is that the page is getting continuosly refreshed, I have used window.location.href to redirect the user to other page, Am I doing something wrong please let me know I have posted the code below

```
import React, { Component } from "react";
import { BrowserRouter, Route, Switch } from "react-router-dom";
import setAuthToken from "./utils/setAuthToken";
import jwtDecode from "jwt-decode";

import store from "./store/store";

import Dashboard from "./components/app/Dashboard";
import HomePage from "./components/homepage/HomePage";
import Navbar from "./components/common/Navbar";
import { UserDetails } from "./components/common/UserDetails";

import { Provider } from "react-redux";
import { logoutUser } from "./store/actions/authActions";
import { setCurrentUser } from "./store/actions/usersActions";

class App extends Component {
  componentDidMount() {
    if (localStorage.getItem("user")) {
      const token = localStorage.getItem("user");

      console.log("token available");
      const decoded = jwtDecode(token);
      var currentTime = Date.now().toString();
      currentTime = currentTime.substring(0, currentTime.length - 3);
      const currentTimeNum = parseInt(currentTime);
      if (currentTimeNum > decoded.exp) {
        console.log("logged out");
        setAuthToken();
        store.dispatch(logoutUser());
        window.location.href = "/home-page";
      } else {
        console.log("logged in");
        setAuthToken(token);
        window.location.href = "/";
        store.dispatch(setCurrentUser());
      }
    } else {
      console.log("logged out");
      setAuthToken();
      window.location.href = "/home-page";
    }
  }

  render() {
    return (
      <Provider store={store}>
        <BrowserRouter>
          <div className="App">
            <Navbar />
            <Switch>
              <Route path="/home-page" component={HomePage} exact />
              <Route path="/" component={Dashboard} exact />
              <Route path="/user/:username" component={UserDetails} exact />
            </Switch>
          </div>
        </BrowserRouter>
      </Provider>
    );
  }
}

export default App;

```