2020-11-30 08:56:17 -08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import Axios from 'axios';
|
2020-11-05 09:15:23 -08:00
|
|
|
import HomePage from "./components/HomePage";
|
2020-11-16 08:48:20 -08:00
|
|
|
import PricingPlan from "./components/PricingPlan";
|
2020-11-09 08:45:04 -08:00
|
|
|
import LogInContainer from "./components/LogInContainer";
|
2020-12-04 08:38:55 -08:00
|
|
|
import { Router,BrowserRouter, Route, Switch } from 'react-router-dom';
|
2020-11-30 08:56:17 -08:00
|
|
|
import UserContext from "./context/UserContext";
|
2020-12-04 08:38:55 -08:00
|
|
|
import Tracking from "./components/Tracking";
|
|
|
|
import Options from "./components/Options";
|
2020-11-30 08:56:17 -08:00
|
|
|
|
|
|
|
export default function App() {
|
|
|
|
const [userData, setUserData ] = useState({
|
|
|
|
token: undefined,
|
|
|
|
user: undefined
|
|
|
|
});
|
|
|
|
useEffect(() => {
|
|
|
|
const checkLoggedIn = async () => {
|
|
|
|
let token = localStorage.getItem("auth-token");
|
|
|
|
if (token == null) {
|
|
|
|
localStorage.setItem("auth-token","");
|
|
|
|
token ="";
|
|
|
|
}
|
|
|
|
const tokenRes = await Axios.post(
|
|
|
|
"http://localhost:5000/users/tokenIsValid",
|
|
|
|
null,
|
|
|
|
{headers: {"x-auth-token": token }}
|
|
|
|
|
|
|
|
);
|
|
|
|
if (tokenRes.data) {
|
|
|
|
const userRes = await Axios.get("http://localhost:5000/users/",
|
|
|
|
{headers:{"x-auth-token":token},
|
|
|
|
});
|
|
|
|
setUserData({
|
|
|
|
token,
|
|
|
|
user: userRes.data,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
checkLoggedIn();
|
|
|
|
|
|
|
|
},[])
|
2020-11-05 09:15:23 -08:00
|
|
|
return (
|
|
|
|
<div className="App">
|
2020-11-13 08:01:37 -08:00
|
|
|
<BrowserRouter>
|
2020-11-30 08:56:17 -08:00
|
|
|
<UserContext.Provider value= {{userData, setUserData}}>
|
2020-11-13 08:01:37 -08:00
|
|
|
<Switch>
|
2020-12-04 08:38:55 -08:00
|
|
|
<Route exact path="/" component={HomePage} />
|
2020-11-18 09:09:20 -08:00
|
|
|
<Route path="/user" component={LogInContainer} />
|
2020-11-19 08:57:07 -08:00
|
|
|
<Route path="/pricing" component={PricingPlan} />
|
2020-12-04 08:38:55 -08:00
|
|
|
<Route path="/track" component={Tracking} />
|
|
|
|
<Route path="/options" component={Options} />
|
2020-11-13 08:01:37 -08:00
|
|
|
</Switch>
|
2020-11-30 08:56:17 -08:00
|
|
|
</UserContext.Provider>
|
2020-11-13 08:01:37 -08:00
|
|
|
</BrowserRouter>
|
2020-11-09 08:45:04 -08:00
|
|
|
|
|
|
|
|
2020-11-05 09:15:23 -08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
2020-11-02 19:10:07 -08:00
|
|
|
|
2020-11-30 08:56:17 -08:00
|
|
|
|