aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-12-21 19:45:57 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-12-21 19:45:57 +0530
commita35176afd7873a317af8b4d3844037ea0233776f (patch)
tree8d4c031b6d04b26b76bc50d511a8a2bdfbe6c820 /src
parent8f228f959d17ae59e08d1de4c19d9d6695a82bed (diff)
made app unaccessible when not logged in
Diffstat (limited to 'src')
-rw-r--r--src/App.js19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/App.js b/src/App.js
index 8dfbf81..197b6f2 100644
--- a/src/App.js
+++ b/src/App.js
@@ -15,9 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { BrowserRouter, Route, Routes } from "react-router-dom";
+import { Route, Routes, useLocation } from "react-router-dom";
+import { useEffect } from "react";
import { ReactNotifications } from "react-notifications-component";
-import "./notifications_styles/notification.scss"
+import axios from "axios";
+import "./notifications_styles/notification.scss";
import Navbar from './components/navbar/navbar';
import HomePage from './views/homepage';
@@ -32,8 +34,17 @@ import ManageInvoicesPage from './views/manage/invoices';
import './App.scss';
const App = () => {
+ // when location changes, ping server to check if logged in
+ // and don't ping if location is /login or /register
+ const location = useLocation();
+ useEffect(_ => {
+ if (!["/login", "/register"].includes(location.pathname)) {
+ axios.post("/ping")
+ }
+ }, [location]);
+
return (
- <BrowserRouter>
+ <>
<Navbar/>
<ReactNotifications />
<main>
@@ -50,7 +61,7 @@ const App = () => {
<Route path="*" element={<h1>404</h1>}/>
</Routes>
</main>
- </BrowserRouter>
+ </>
);
}